[GLLUG] grep help

Hampton, Rodney rodney.hampton at jnli.com
Wed May 11 15:25:45 EDT 2005


You could use sed, tee, etc. to accomplish this.  Just looking at your
output and piping it to a little perl will strip off the top line and the
bottom 3 lines for you.  I'm sure, with some imagination, you could do the
whole thing in perl.

:-)


where junk.txt is the sample data you have provided.

$ cat junk.txt|perl -e 'my $flag=0;while(<>){if($_ =~/Total Files
Listed/){$fla
g=1;}if ($_ =~/Current Machine/ or $flag){print $_;}}'

Current Machine: whoeverthemachinebelongsto
      Total Files Listed:
               96 File(s)    376,092,645 bytes
                0 Dir(s)  30,038,294,528 bytes free





Regards,






Rodney Hampton
http://www.hamptonandassociates.net

-----Original Message-----
From: Mike Szumlinski [mailto:szumlins at mac.com]
Sent: Wednesday, May 11, 2005 2:59 PM
To: gllug list
Subject: [GLLUG] grep help


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

_______________________________________________
linux-user mailing list
linux-user at egr.msu.edu
http://www.egr.msu.edu/mailman/listinfo/linux-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.egr.msu.edu/mailman-archives/linux-user/attachments/20050511/1785dab1/attachment.htm


More information about the linux-user mailing list