[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Field separators in awk
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] Field separators in awk |
Date: |
Tue, 31 Dec 2013 10:32:24 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Tue, Dec 31, 2013 at 09:47:42AM -0500, Andrew J. Schorr wrote:
> That sets the field separator to the new line character (i.e. the same as RS).
>
> bash-4.2$ awk '-F\n' 'BEGIN {print FS; print RS}' | od -c
> 0000000 \n \n \n \n
> 0000004
>
> bash-4.2$ echo 'this is a test' | awk '-F\n' '{print NF; print $1}'
> 1
> this is a test
FYI, another way of accomplishing this is like so:
bash-4.2$ awk 'BEGIN {FS = RS; print RS; print FS}' | od -c
0000000 \n \n \n \n
0000004
bash-4.2$ echo 'this is a test' | awk 'BEGIN {FS = RS} {print NF; print $1}'
1
this is a test
This is more verbose, but perhaps more clear than saying '-F\n'.
But as I pointed out previously, it should suffice simply to access $0.
There should be no performance penalty if you access only $0.
Regards,
Andy