[GLLUG] grep help

STeve Andre' andres at msu.edu
Wed May 11 15:06:41 EDT 2005


On Wednesday 11 May 2005 14:59, Mike Szumlinski wrote:
> Okay, I'm trying to parse a large amount of report files for some
> people here at work and I'm pretty sure grep is the tool I need.  The
> one thing I don't know how to do is throw away some of the information
> I'm getting.
>
> Right now, my expression is as follows:
>
> ---
>
> myhost:~/Desktop] szumlins% grep "Current\ Machine\|Total\
> Files\|bytes" sometextfile.txt
> Current Machine: whoeverthemachinebelongsto
>                 1 File(s)      3,492,199 bytes
>                 2 File(s)      1,374,386 bytes
>                14 File(s)     60,253,470 bytes
>                12 File(s)     66,581,162 bytes
>                16 File(s)     42,781,520 bytes
>                16 File(s)     60,159,760 bytes
>                 5 File(s)     17,112,793 bytes
>                12 File(s)     54,080,486 bytes
>                17 File(s)     67,632,351 bytes
>                 1 File(s)      2,624,518 bytes
>       Total Files Listed:
>                96 File(s)    376,092,645 bytes
>                 0 Dir(s)  30,038,294,528 bytes free
>
> ---
>
> All of the text files have "Current Machine:" in the first line.  All
> of the text files also have "Total Files Listed:" and then the
> information as the last 3 lines.  I only want that information, not all
> the individual files above.  Any quick ideas how I can slap that
> request back into a regexp and eliminate the multiple lines so that my
> output looks like this:
>
> ---
>
> Current Machine: whoeverthemachinebelongsto
>
>       Total Files Listed:
>                96 File(s)    376,092,645 bytes
>                 0 Dir(s)  30,038,294,528 bytes free
>
> ---
>
> I'm sure this is a quickie for some of you guys, I really appreciate
> the help.
>
> -Mike

If I am understanding you, then all you want is the last three lines
of output?  If that is the case, you can use the tail command, like so

   grep blah blah blah | tail -3

The cool cool thing about the shell is that you have all these little
programs, like grep, head, tail, awk, sed, cut, etc that are tools
that do on thing, which can be tacked together for a custom tool.

--STeve Andre'


More information about the linux-user mailing list