Check all files in directories for string and remove.. possible?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check all files in directories for string and remove.. possible?
# 1  
Old 11-29-2005
Check all files in directories for string and remove.. possible?

Say I am in /var/adm/bin and I want to search through all the various scripts and such in that directory for a string, say, xxx@yyy.com

I want to find every file with that in there and replace it with a single space.

Is that possible?

Or, is it possible to search every file and get a list of what files have that in there?

If I do a more * | grep xxx@yyy.com I get a list of all the lines with that in there but no reference to the file name.

Anyone have any ideas?
LordJezo
# 2  
Old 11-29-2005
for starters:
Code:
grep -l 'xxx@yyy.com' *

# 3  
Old 11-29-2005
you could also do ...

grep xxx@yyy.com *
# 4  
Old 11-29-2005
i just read the original post ...

this is in ksh ...
Code:
for file in `grep -l xxx@zzz.com *`
do
    sed "s/xxx@zzz.com/ /g" $file > /tmp/123
    cat /tmp/123 > $file
    rm /tmp/123
done

# 5  
Old 11-29-2005
perl:

$ perl -pi -e 's|bar\@mydomain.com||g' *

use -pi.bak if u need to backup your original files (will renamed as .bak)
# 6  
Old 11-29-2005
or:
Code:
#!/bin/ksh
for i in $(grep -l 'xxx@zzz.com' *)
do 
  (/bin/echo '%s/xxx@zzz.com/ /g\nwq!') | ex - ${i}
done;

# 7  
Old 11-30-2005
Quote:
Originally Posted by vgersh99
for starters:
Code:
grep -l 'xxx@yyy.com' *


This wont work if you have subdirectories with files inside them.
In which case you could use something like this:

grep "pattern" `find /path -name * -print`
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete Directories and its files that begin with the same character string

I wrote a shell script program that supposed to delete any directories and its files that begin with the same character string . The program is designed to delete directories and its files that are one day old or less and only the directories that begin with the same character string. The problem... (1 Reply)
Discussion started by: dellanicholson
1 Replies

2. Shell Programming and Scripting

Remove files in directories

I am trying to remove files from a couple of directories after a process completes. Below is what I have so far, but the command does not run and cygwin closes too fast to read the error. Also, is it possible to have the printf be displayed until the files are removed then printf in italics is... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. AIX

How to remove ISMP files when the directories have been deleted?

Hello all, I've been asked to help with some cleanup on a couple of systems that were running some Websphere apps. I need to remove the following filesets: mqsi61.cfgmgrc 6.1.0.2 COMMITTED Config. Manager Component mqsi61.cfgmgrf 6.1.0.2 COMMITTED Config.... (4 Replies)
Discussion started by: ZekesGarage
4 Replies

4. Shell Programming and Scripting

.sh script / Check for file in two directories then cat the files

Hi, Here is what i'm trying to do, -Check in two directories for a user inputed filename -Then cat all the version found of the file to the current screen I am a total nembie to programming, here what i have done so far.... #!/bin/bash #Check in /home/loonatic and /var/named/master... (2 Replies)
Discussion started by: Loonatic
2 Replies

5. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

6. Shell Programming and Scripting

Check file size and remove files

Hi, Here we have a situation where we have to check the file size and if the file size is greater than 0 bytes then remove the files from the directory. 1)EdwTrxn 2)EdwPost 3)EdwTndr 4)EdwSls 5)EdwSlsRej 6)EdwTndrRej Files will be created in the directory in the following manner. ... (5 Replies)
Discussion started by: srivsn
5 Replies

7. Shell Programming and Scripting

read list of filenames from text file and remove these files in multiple directories

I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
Discussion started by: fxvisions
5 Replies

8. Shell Programming and Scripting

Need to remove files older than 30 days except directories

Hi, I need to remove files (*.trc) which are older than 30 days from one location. My problem is there I do not want to visit any of the directories at that location. I want to search files at that particular location only (need to skip directorys at that location). maxdepth option is there... (6 Replies)
Discussion started by: malaymaru
6 Replies

9. Shell Programming and Scripting

How to Remove Ctrl M characters in files from directories and its subdirectories

Hi, How to recursively remove Ctrl M characters in files from a directory and its sub directory ? I know unix2dos command is there but to remove in bunch of files ... ? Thanks (7 Replies)
Discussion started by: skdp
7 Replies

10. UNIX for Dummies Questions & Answers

What/How to check before deleting files and directories

Hi there, I have a some directories containing web files that are old, and I need to remove them. I know that there might be sym links and hyperlinks pointing to these old directories. If that's the case, then I'll have to fix the links before deleting these old directories to avoid broken... (4 Replies)
Discussion started by: yvochan
4 Replies
Login or Register to Ask a Question