I'm trying to read multiple files in an AWK-script but when I change between file, the field seperator (FS) needs to change as well. At this point I got:
FILENAME=="A.txt"{
FS=";"
//DoSomething
}
FILENAME=="B.txt"{
FS=" - "
//DoSomething
}
But as you might know, the FS will not get set correctly for the first line of the file. How can I solve this?
You can specify the field separators at the command line:
awk -f a.awk FS=";" A.txt FS=" - " B.txt
In this way, the field separator will change for each file. From http://www.delorie.com/gnu/docs/gawk/gawk_82.html :
Any awk variable can be set by including a variable assignment among the arguments on the command line when awk is invoked
and
With it, a variable is set either at the beginning of the awk run or in between input files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With