I am trying to do the following:
- Read the file line by line.
- Each row has the following structure:
field1;field2;field3
- Use
awk
to separate each of these fields, and then process each of these fields further.
The code snippet I have is:
while read l do n=`echo ${l} | awk --field-separator=";" '{print NF}'` field1=`echo ${l} | awk --field-separator=";" '{print $1}'` field2=`echo ${l} | awk --field-separator=";" '{print $2}'` field3=`echo ${l} | awk --field-separator=";" '{print $3}'` echo ${n} ${field1} ${field2} ${field3} done < temp
If temp contains only the following line:
xx;yy;zz
The answer I get on the command line is:
1 xx;yy;zz
I am not sure I understand this conclusion. Any explanation would be nice, given that it works for other files. I am working on a Mac while this code uses awk
inside a bash
script.
source share