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
String Replacement Script jbud Shell Programming and Scripting 6 11-15-2007 06:37 AM
String Replacement with Perl Lindarella Shell Programming and Scripting 4 09-29-2006 02:05 PM
sed problem - replacement string should be same length as matching string. amangeles Shell Programming and Scripting 4 01-11-2006 06:11 AM
grep, sed in a shell script Trufla Shell Programming and Scripting 4 04-07-2005 08:57 AM
String replacement in multiple files WABonnett Shell Programming and Scripting 2 02-17-2004 03:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-15-2007
pranavagarwal pranavagarwal is offline
Registered User
  
 

Join Date: Oct 2007
Location: India
Posts: 29
Exclamation Need shell/sed script for grep+string replacement

Hi,

Let me explain the situation.

There are many files in a directory and its sub-directories that conatin the string pattern "pa". I want to replace all such instances with the pattern "pranavagarwal"

doing a
Code:
grep "pa" `ls`
does give me all the instances of the occurence of that paatern.

Do i need a sed script in conjunction with this grep to replace all occurences?
What options do i have to do it, I mean, can I do it in more than one way?
  #2 (permalink)  
Old 11-15-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
Code:
find . -type f | xargs sed -i 's/pa/pranavagarwal/g'
be careful though, pa would also match parrot and darpan

Last edited by Yogesh Sawant; 11-15-2007 at 05:05 AM..
  #3 (permalink)  
Old 11-15-2007
pranavagarwal pranavagarwal is offline
Registered User
  
 

Join Date: Oct 2007
Location: India
Posts: 29
not good enough..

thank you for the post friend,
but the msg i got is..
Code:
sed: illegal option -- i
i know the mistake is mine.
I didn't specify that I'm working on SunOS SPARC version of Unix. may be that's why the -i didn't work.

another thing.. do remember that i want to do it for files in all sub-directories as well..

thank you and ciao!

Last edited by pranavagarwal; 11-15-2007 at 06:06 AM.. Reason: added OS details
  #4 (permalink)  
Old 11-15-2007
vino's Avatar
vino vino is online now Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by Yogesh Sawant View Post
Code:
find . -type f | xargs sed -i 's/pa/pranavagarwal/g'
be careful though, pa would also match parrot and darpan
Perl ?

Code:
find . -type f | xargs perl -pi -e 's/pa/pranavagarwal/g'
Closed Thread

Bookmarks

Tags
gnu sed, xargs

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 05:12 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