[TriLUG] Need some help parsing a file
John Vaughters
jvaughters04 at yahoo.com
Mon Dec 30 09:28:40 EST 2013
+1 on using cut
I like simplicity and sometimes the older tools like cut which are used in just about all Unix dist. are the best. What I like about cut is that it is easy to remember how to use. No time wasted looking up or creating regex. Great for on the fly work.
cat filename.txt | cut -d ' ' -f 8
This uses a delimiter of {space} and field 8. what I like about this method is you can cut multiple times with further delimiters. This can come in handy on complex files like html.
For example you could do this although necessary for you needs, but just to illustrate.
cat filename.txt | cut -d ':' -f 2 | cut -d ' ' -f 7
awk would be my next choice.
cat filename.txt | awk '{print $8}'
Also simple, but for some reason, I cannot remember it as easy as cut.
Disclaimer:
I did not actually try the commands. But just as I do on the fly when working on things like this is to try and adjust. I often get the wrong field on first try.
John Vaughters
More information about the TriLUG
mailing list