The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check file size and remove files srivsn Shell Programming and Scripting 5 05-28-2009 01:09 PM
read list of filenames from text file and remove these files in multiple directories fxvisions Shell Programming and Scripting 5 08-07-2008 03:59 PM
Need to remove files older than 30 days except directories malaymaru Shell Programming and Scripting 6 11-13-2006 11:50 PM
How to Remove Ctrl M characters in files from directories and its subdirectories skdp Shell Programming and Scripting 7 07-29-2006 11:53 PM
What/How to check before deleting files and directories yvochan UNIX for Dummies Questions & Answers 4 07-29-2005 09:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-29-2005
LordJezo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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?
  #2 (permalink)  
Old 11-29-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
for starters:
Code:
grep -l 'xxx@yyy.com' *
  #3 (permalink)  
Old 11-30-2005
Abhishek Ghose Abhishek Ghose is offline
Registered User
  
 

Join Date: Sep 2005
Location: Chennai
Posts: 81
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`
  #4 (permalink)  
Old 11-30-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by Abhishek Ghose
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`
you're right, but read the original post, pls!
  #5 (permalink)  
Old 11-29-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
you could also do ...

grep xxx@yyy.com *
  #6 (permalink)  
Old 11-29-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
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
  #7 (permalink)  
Old 11-29-2005
ashterix ashterix is offline
Registered User
  
 

Join Date: Nov 2005
Location: cyberjaya
Posts: 85
perl:

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

use -pi.bak if u need to backup your original files (will renamed as .bak)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0