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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find files which has more than one occurance of pattern Prahlad Shell Programming and Scripting 10 08-08-2008 12:16 PM
Find a pattern and replace using sed. maridhasan Shell Programming and Scripting 5 09-18-2007 01:43 AM
find pattern and replace another field sergiioo Shell Programming and Scripting 3 04-11-2007 12:19 AM
find and replace a pattern in a file krishnamaraju Shell Programming and Scripting 1 08-29-2006 10:02 AM
how find and replace into different files ran UNIX for Dummies Questions & Answers 1 03-18-2005 03:18 AM

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 02-28-2001
tamer tamer is offline
Registered User
  
 

Join Date: Jan 2001
Posts: 9
Question

Hi

How can I looking for a pattern found in more than one file and replace it with anther pattern

this what I was used:

find . -name "account.adrs" -depth -follow -exec grep -l "Email = ;" {} \;

this print the files name -which is account.adrs- and its path -which is deferent for each file- which contains the pattern "Email = ;"

I need to replace this pattern by:
"Email = \"\" ;"

please help
  #2 (permalink)  
Old 02-28-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
There are a few ways to do this. One example:

#!/bin/ksh

FILES=`find . -name account.adrs -depth -follow -exec grep -l "Email = ;" {} \;`

for file in $FILES; do
perl -p i.bak -e 's/Email = ;/Email = \"\" ;/' $file
done



  #3 (permalink)  
Old 03-01-2001
mib mib is offline
Registered User
  
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
Quote:
perl -p i.bak -e 's/Email = ;/Email = \"\" ;/' $file
This generates an error for me "Can't open Perl script i.bak".

Does it mean we need a perl script named "i.bak" to do this task. I am not good at perl from command line.


here is another script. little modification from PxT's Script

#!/bin/sh

FILES=`find . -name "account.adrs" -depth -follow -exec grep -l "Email = ;" {} \;`

for file in $FILES; do
sed -e 's/Email = ;/Email = \"\" ;/' $file > temp
mv -f temp $file
done



  #4 (permalink)  
Old 03-01-2001
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,698
The i.bak is a directive to create backups of the original file with an extension of '.bak'. This helps insure that if you make mistake in your PERL filter, you have a backup of the original (always a good idea !). I did not check the exact syntax in the example code provided.
  #5 (permalink)  
Old 03-03-2001
mib mib is offline
Registered User
  
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
Thank you for info Neo.

error I made was, I put space between -p and i.bak.

it should be -pi.bak(without space) or -p -i.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 06:38 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