On 9/16/2016 8:09 AM, Marc de Bourget wrote:
> Le vendredi 16 septembre 2016 14:47:58 UTC+2, Kenny McCormack a écrit :
>> Marc de Bourget wrote:
>>> This might be a strange question or there may be an obvious solution.
>>> Anyway: How to assign the default field separator of AWK to FS?
>>
>> The short answer is: FS = " "
>>
>> Or you could start by doing:
>>
>> $ gawk 'BEGIN {print FS}'|od -bc
>> 0000000 040 012
>> \n
>> 0000002
>> $
>>
>> --
>> To most Christians, the Bible is like a software license. Nobody
>> actually reads it. They just scroll to the bottom and click "I agree."
>>
>> - author unknown -
>
> Great! Thank you both Kenny and Geoff.
> I wasn't aware that FS = " " can be used for the default separator
> and includes both tabs and spaces.
It does more than that though, otherwise you could just write FS="[[:blank:]]+"
or FS="[ \t]+", specifying the default FS also skips leading and trailing white
space so given this input:
a b
with FS=" " NF is 2 and "a" is $1 while with FS="[[:blank:]]+" NF is 3 and "a"
is $2:
$ echo ' a b' | awk -F' ' '{print NF, "<" $1 ">"}'
2 <a>
$ echo ' a b' | awk -F'[ \t]+' '{print NF, "<" $1 ">"}'
3 <>
Hopefully you came across that in your research but since you seem to be new to
using awk I figured it was worth mentioning before it bites you later :-).
Ed.