home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7371 < prev    next >
Encoding:
Internet Message Format  |  1992-12-11  |  1.3 KB

  1. Path: sparky!uunet!noc.near.net!hri.com!spool.mu.edu!caen!destroyer!gumby!wupost!cs.utexas.edu!sun-barr!male.EBay.Sun.COM!jethro.Corp.Sun.COM!jethro!eric
  2. From: eric@animus.Corp.Sun.COM (eric )
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Delete until pattern match
  5. Message-ID: <ERIC.92Dec11142621@animus.Corp.Sun.COM>
  6. Date: 11 Dec 92 19:26:21 GMT
  7. References: <3722@symbas.UUCP>
  8. Organization: /home1/eric1/.organization
  9. Lines: 25
  10. NNTP-Posting-Host: animus.corp.sun.com
  11. In-reply-to: hans@symbas.UUCP's message of 11 Dec 92 18:46:09 GMT
  12.  
  13. In article <3722@symbas.UUCP> hans@symbas.UUCP (Hans Aafloy) writes:
  14.  
  15.   >    From: hans@symbas.UUCP (Hans Aafloy)
  16.   > 
  17.   >    I have some files in which I want to delete all lines until a
  18.   >    certain pattern match. I know a couple of awkward ways to do it,
  19.   >    ( using an array as temporary storage etc.) 
  20.   >    but is there a quicker and more elegant solution ?
  21.   > 
  22.   >    Thanx for any hints - via e-mail please.
  23.   > 
  24.   >    Hans
  25.   > 
  26.   >    hans@symbas.lind.no 
  27.  
  28. I think this is exactly what I was just asking about a few message ago.  The
  29. answer is:
  30.  
  31.   perl -ni.old -e 'print unless ( 1 .. /^---cut here---/ ); close(ARGV) if eof' file1 file2
  32.  
  33. What this does it go through all files ("file1", "file2", etc.), and
  34. remove everything up to and including the pattern "---cut here---", and
  35. rename the original file "file1.old", etc.
  36.  
  37. -Eric
  38.