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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using grep and rm command in a script

Status
Not open for further replies.

unmlobo

MIS
Apr 11, 2003
64
US
I was wondering if anyone could tell me how to use the grep command and the rm command together. I have a .txt file that I need to edit lines from. I can grep for those lines but I need to pipe/redirect them to the rm command to get rid of them. Example:

grep word (filename) | rm

Any ideas?

Thanks a million!
 
Try this instead -

grep -v word (filename) the -v switch tells grep to return every line that does not have the value from there you can redirect the output to a file once you are sure it is what you are looking for.

grep -v word (filename) > mynewfile


HTH,

Steve
 
Thanks a million Steve. It worked perfectly! Now is there a way to get the contents sorted in alpha order. The contents of the file is created with the basic who command. No flags.
 
Try this :

grep -v word (filename) | sort > mynewfile

Jean Pierre.
 
Thank you both so very much! You saved me major stress.
 
Glad I could help. There are several more ways to do what you wanted but I try to keep things simple so I will not forget how I did them.

:)


Steve
 
Answer to the original post:
Code:
grep word (filename) | xargs rm

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top