[TriLUG] Need some help parsing a file
Brian McCullough
bdmc at buadh-brath.com
Mon Dec 30 10:07:12 EST 2013
On Mon, Dec 30, 2013 at 06:28:40AM -0800, John Vaughters wrote:
> +1 on using cut
"Me too."
> 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
And, you are also illustrating at least a couple of the basic tenets of Unix.
-- Use the most appropriate tool for the job
-- Lots of little, specialized tools that do one thing well
-- Don't forget pipes.
( The oldest, and sometimes most useful, commands in Unix are the
shortest. Originally, Unix was "talked to" with Teletype machines (
terminals ), which were very slow and clunky to type on, -- cylindrical
keys with a LOT of vertical movement -- so the developers tried to type
as little as possible. )
Brian
More information about the TriLUG
mailing list