gawk into an array question

Doug dougsweetser-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Tue Jan 27 09:58:40 EST 2009


Hello:

This is not the answer to the question, but another way, as is the way in Unix.

If one is rusty with awk, this is the perl one-liner that gets at the
first argument:

$ perl -F, -lane 'print $F[0]' test.csv
catname1.dat
foo.txt
foo1.txt
foo2.txt
foo3.txt
foo4.txt

-lane is easy to remember, kind of like lanes of traffic.  I had to
look up -F that defines the separator, in this case a comma.  The
variable created by this process is the array @F, so I guess in makes
sense to make the separator option with -F.  Inside the single quotes,
one could do more Perl string manipulation if needed, like joining
with the 3rd argument $F[2], if needed.

Doug





More information about the Discuss mailing list