Utilities Blog by JuCa Cruz
If it happened to me before, maybe what I've posted here will help you.
Showing posts with label
Shell Scripting
.
Show all posts
Showing posts with label
Shell Scripting
.
Show all posts
Friday, February 4, 2011
Read File using Unix Shell
This is something really small which could be useful in case you want to read a comma separated file and use each line (on this case to call an external program passing as parameter each field value)
#!/usr/bin/env ksh93 fileName=/tmp/data.csv echo echo "################### $(date) #####################" echo [ ! -f ${fileName} ] && echo "ERROR: Exiting as ${fileName} not found!!" && exit 1 while read line; do field1=$(echo $line | awk -F "," '{print $1}') field2=$(echo $line | awk -F "," '{print $2}') field3=$(echo $line | awk -F "," '{print $3}') echo ${field1} ${field2} ${field3} ## external command goes here done < ${fileName}
Older Posts
Home
Subscribe to:
Posts (Atom)