[TriLUG] Need some help parsing a file
Brian Blater
brb.lists at gmail.com
Mon Dec 30 09:42:56 EST 2013
On Mon, Dec 30, 2013 at 9:28 AM, John Vaughters <jvaughters04 at yahoo.com>wrote:
> +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
>
I tried this one after trying the first example of cut and yeah, I think
I'll have to play with the field variable.
Brian
More information about the TriLUG
mailing list