robin
August 18, 2011, 3:46pm
1
Yes, I think it does what I think it does. THis prints the
separator as I would expect it to:
echo -e "#separator ;\n1;2;3;4\n" | awk '/#separator / {FS=$2; print $2}'
But it doesn't apply the new FS, at least on my Mac awk.
Anyway, let's just pick something and go ahead. I still prefer the
whitespace here[1] so why don't we always make the first line look
like this
{{{
#seperator \t
}}}
(Indeed with the standard C escaping for non-printable characters).
[1] Because the escaping makes sure there's no whitespace in the
separator itself.
Yes, I think it does what I think it does. THis prints the
separator as I would expect it to:
echo -e "#separator ;\n1;2;3;4\n" | awk '/#separator / {FS=$2; print $2}'
But it doesn't apply the new FS, at least on my Mac awk.
I don't know but it works on mine. What's the problem you are facing? The new FS will only apply to the following lines, not the current one. (And you'll also need a rule for lines without /#separator /):
$ echo -e "#separator ;\n1;2;3;4\n" |\
awk '/#separator / {FS=$2; print "sep",$2} !/#separator / { print "field3",$3} '
sep ;
field3 3
field3
$ uname -a
Darwin tongariro 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 i386
$ which awk
/usr/bin/awk
cu
Gregor