Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Script

Status
Not open for further replies.

abovebrd

IS-IT--Management
May 9, 2000
690
US
<br>I need to find a way to a delete a series of files that have a matching&nbsp;&nbsp;general expression in each file. The matching expression would be **TOTAL 0.00**<br><br>This expression would always be the third line from the end of the file. The expression **TOTAL 0.00** would always be at the end of that line. <br><br>In the directory that these files are kept there are usually around 1,000 files that need to be searched. Once the expression is matched in a file I need to move the file to a new directory and or simply delete the file. <br><br>I think because of the pattern matching I am trying to do AWK would be a good place to start. At this point I am not familiar enough with AWK to put it all together.<br><br>Any thoughts or help would be appreciated.<br><br>Thanks<br><br>Danny<br><A HREF="mailto:dannyd@aboveboardelectronics.com">dannyd@aboveboardelectronics.com</A><br> <p>Danny Daniels<br><a href=mailto:dannyd@aboveboardelectronics.com>dannyd@aboveboardelectronics.com</a><br><a href= > </a><br>
 
Assuming the 1000-ish files are all in the same directory, try this:<br><FONT FACE=monospace><br>rm `grep -l &quot;\*\*TOTAL 0.00\*\*&quot; *`<br></font><br>The &quot;grep -l&quot; will return a list of files containing the regexp.&nbsp;&nbsp;Put it in backtics (`) and prefix it with rm, and you can remove all the files containing the text.<br><br>I've done a limited test on this, so I'd test it on a copy of your data first before using it &quot;live&quot;. <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top