I have a text file with 9 fields separated by :
survey:m1111771::rent:travel:::Morning:
How do I pull field 1 and 8 only to a separate file
for example it would look like this,
survey:Morning
I have a text file with 9 fields separated by :
survey:m1111771::rent:travel:::Morning:
How do I pull field 1 and 8 only to a separate file
for example it would look like this,
survey:Morning
:
character is OK when you're only printing two fields, but it gets tedious and error-prone very quickly if you want to print more fields. It's better to set the Output Field Separator (OFS) to:
. e.g.awk -F: -v OFS=: '{print $1,$8}'
. hard-coding it is also a pain if you ever want to change it (e.g. to a tab or a comma), as you'd then have to manually change every occurrence. – cas May 19 '16 at 00:14