in reply to making a single column out of a two-column text file
As a one-liner:
perl -ne '/(\S*)\s+(\S*)/; push @a,$1 if length $1; push @b,$2 if length $2; END{ print "First column output:\n\n@a\n\nSecond column output:\n\n@b\n\n" }'And more readably:
while (<>) { # Added a conditional per merlyn's advice /(\S*)\s+(\S*)/ or next; # /(\S*)\s+(\S*)/; push @a, $1 if length $1; push @b, $2 if length $2; } print "First column output:\n\n@a\n\n", "Second column output:\n\n@b\n\n"
Seeking Green geeks in Minnesota
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Re: making a single column out of a two-column text file
by merlyn (Sage) on Feb 26, 2003 at 01:54 UTC | |
by diotalevi (Canon) on Feb 26, 2003 at 01:56 UTC | |
by merlyn (Sage) on Feb 26, 2003 at 02:20 UTC | |
|
Re: Re: making a single column out of a two-column text file
by hv (Prior) on Feb 26, 2003 at 02:36 UTC | |
by jasonk (Parson) on Feb 26, 2003 at 02:45 UTC | |
|
Re: Re: making a single column out of a two-column text file
by allolex (Curate) on Feb 26, 2003 at 03:41 UTC | |
by diotalevi (Canon) on Feb 26, 2003 at 05:18 UTC |