Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

What is find and replace command in unix?

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-14-2010
rajkumar_g rajkumar_g is offline
Registered User
 
Join Date: Oct 2010
Last Activity: 8 December 2010, 5:24 AM EST
Posts: 32
Thanks: 6
Thanked 0 Times in 0 Posts
What is find and replace command in unix?

hello forum memvers,


1:I have to write a script for find a string and replace with another string.
2:In shell script how to replace one string with another string.Linux
Sponsored Links
    #2  
Old Unix and Linux 10-15-2010
durden_tyler's Unix or Linux Image
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
 
Join Date: Apr 2009
Last Activity: 15 August 2017, 11:40 AM EDT
Posts: 2,067
Thanks: 20
Thanked 372 Times in 336 Posts
Quote:
Originally Posted by rajkumar_g View Post
...
1:I have to write a script for find a string and replace with another string.
2:In shell script how to replace one string with another string.
Post your script over here and we'll look into it.
If you do not have a script ready, then try writing one first and then post it over here if you get stuck.

tyler_durden
Sponsored Links
    #3  
Old Unix and Linux 10-15-2010
rajkumar_g rajkumar_g is offline
Registered User
 
Join Date: Oct 2010
Last Activity: 8 December 2010, 5:24 AM EST
Posts: 32
Thanks: 6
Thanked 0 Times in 0 Posts
thanks for suggestion

I know find command to search a string but i dont know how to replace with other string. for example.
i am finding for Hosts.
find . -type f -exec grep -l "Hosts" {} \;
but idont know how to replace with "Server".


Thanks & Regards
Rajkumar g
    #4  
Old Unix and Linux 10-15-2010
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 29 May 2017, 3:44 AM EDT
Location: France
Posts: 2,956
Thanks: 85
Thanked 632 Times in 603 Posts
Are you willing to rename files ?
or do you just want to generate a list of modified filename in it ?
Sponsored Links
    #5  
Old Unix and Linux 10-15-2010
gary_w's Unix or Linux Image
gary_w gary_w is offline
Registered User
 
Join Date: Oct 2010
Last Activity: 1 March 2017, 9:53 AM EST
Posts: 446
Thanks: 32
Thanked 96 Times in 88 Posts
Here's one way


Code:
for file in *
do
   sed "s/Hosts/Server/g" $file > tmpfile && mv tmpfile $file
done

Gary
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find and replace command prakash.gr Shell Programming and Scripting 1 12-07-2009 03:21 PM
Sed command to find, manipulate and replace a number LT_2008 Shell Programming and Scripting 6 11-13-2008 10:28 AM
find and replace command in one line using one command vasikaran UNIX for Dummies Questions & Answers 10 08-20-2008 10:40 AM
how to use sed or perl command to find and replace a directory in a file wip_vasikaran UNIX for Dummies Questions & Answers 1 08-20-2008 06:22 AM
Little bit weired : Find files in UNIX w/o using find or where command jatin.jain Shell Programming and Scripting 10 09-19-2007 06:47 AM



All times are GMT -4. The time now is 10:00 PM.