|
Printing columns of information from text files is easy, especially using tools like awk, perl, and more recently, ruby. Here's my old school awk way of doing this.
Suppose you have a file named foo with contents like this:
1 2 3
a b c
You can easily use awk to print columns of information from this file. As it doesn't need much introduction, here is a variety of examples showing how to print columns of data from the file. My commands are always preceded by my command line prompt ("prompt>").
prompt> cat foo
1 2 3
a b c
prompt> awk '{ print $1 }' foo
1
a
prompt> awk '{ print $2 }' foo
2
b
prompt> awk '{ print $3 }' foo
3
c
prompt> awk '{ print $1, $3 }' foo
1 3
a c
prompt> awk '{ print $3, $1 }' foo
3 1
c a
As you can see you can print any column you want, and can print the columns in any order you want.
Now, if this doesn't work for you, and you need a little more horsepower, you can follow this link for a powerful method of column oriented data extraction with Perl.
|