find a word in a file and remove it
Hi, I need to find a word in a file then remove it. I'm doing the following, but with no luck, thanks. 'find /var/spool/mqueue/ -type f|xargs grep toulon -exec rm {} \;' TIA
On Monday 15 November 2004 16:50, Patrick B. O'Brien wrote:
Hi,
I need to find a word in a file then remove it.
Does 'it' refer to the word or the entire file? Based on what you tried below I'm assuming you want to delete the whole file
I'm doing the following, but with no luck, thanks.
'find /var/spool/mqueue/ -type f|xargs grep toulon -exec rm {} \;'
find /var/spool/mqueue/ -type f -exec grep toulon {} \; -exec rm {} \;
On Mon, 2004-11-15 at 10:50, Patrick B. O'Brien wrote:
Hi,
I need to find a word in a file then remove it. I'm doing the following, but with no luck, thanks.
'find /var/spool/mqueue/ -type f|xargs grep toulon -exec rm {} \;'
If you want to change the contents of text files try using sed instead. It has been to long since I have used it to give an example. man sed or info sed may be of some help. -- Ken Schneider UNIX since 1989 SuSE since 1998 * Only reply to the list please*
Ken wrote regarding 'Re: [SLE] find a word in a file and remove it' on Mon, Nov 15 at 11:30:
On Mon, 2004-11-15 at 10:50, Patrick B. O'Brien wrote:
Hi,
I need to find a word in a file then remove it. I'm doing the following, but with no luck, thanks.
'find /var/spool/mqueue/ -type f|xargs grep toulon -exec rm {} \;'
If you want to change the contents of text files try using sed instead. It has been to long since I have used it to give an example. man sed or info sed may be of some help.
To remove just the string: perl -i -pe's/toulon//g' file1 file2 file3 fileN or find /path -type f -exec perl -i -pe's/toulon//g' '{}' \; Note that knowing what that regexp matches is a very important thing to do before running such a command line! --Danny, a big fan of the in-place edit flag :)
Patrick B. O'Brien wrote:
Hi,
I need to find a word in a file then remove it. I'm doing the following, but with no luck, thanks.
'find /var/spool/mqueue/ -type f|xargs grep toulon -exec rm {} \;'
TIA
Hi Patrick, I guess that you'll find your way out using 'sed' instead ... HTH, Martin
Patrick wrote regarding '[SLE] find a word in a file and remove it' on Mon, Nov 15 at 10:21:
Hi,
I need to find a word in a file then remove it. I'm doing the following, but with no luck, thanks.
'find /var/spool/mqueue/ -type f|xargs grep toulon -exec rm {} \;'
remove the file? If you don't have spaces in the files (which is teh case in your example, too), I'd do something like: for F in `grep -rl toulon /var/spool/mqueue/`; do rm -i $F; done That'll prompt before deletions, so you don't kill any files that you don't want to kill. --Danny
participants (5)
-
Anders Johansson
-
Danny Sauer
-
Ken Schneider
-
Martin Mielke
-
Patrick B. O'Brien