What is find and replace command in unix?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is find and replace command in unix?
# 1  
Old 10-15-2010
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.Smilie
# 2  
Old 10-15-2010
Quote:
Originally Posted by rajkumar_g
...
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
# 3  
Old 10-15-2010
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 10-15-2010
Are you willing to rename files ?
or do you just want to generate a list of modified filename in it ?
# 5  
Old 10-15-2010
Here's one way

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

Gary
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command + replace the extension (.xxx) by *

Hello, I'm on HP Unix and in a Job, I tried to extract all files from a folder, and replace the extension (.xxxx) by '*' , remove duplicates and move the result in a file.. Example : Folder has : ABC, CCC.txt, CCC.sf, CCC.sfd, DDD I need to generate and output file with : ... (6 Replies)
Discussion started by: royinfo.alain
6 Replies

2. Shell Programming and Scripting

Find and Replace in UNIX Scripting

Hi, Need your advices, Input : select code,status,input from VIEW1.VIEWNAME where IDU_CD IN ('S','N') and status_col='derived')) union select code,status,input from VIEW1.VIEWNAME2 where date='#p1' Expected output : select code,status,input from VIEW1.VIEWNAME where... (2 Replies)
Discussion started by: Nandy
2 Replies

3. UNIX for Dummies Questions & Answers

Find and Replace string in UNIX

Hi All, Greetings. I have a .dat file which somewhere in its content contains symbol ""^ I want to replace it with "^ I tried with SED command but could not achieve what i wanted sed -e "s/'""^'/'"^'/ig" filename.dat (5 Replies)
Discussion started by: MaddyS
5 Replies

4. Shell Programming and Scripting

Find and replace using sed command

The content of the file filea.txt is as follows. --------- case $HOSTNAME in aaa) DS_PARM_VALUE_SET=vsDev APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt ;; bbb) DS_PARM_VALUE_SET=vsQA... (3 Replies)
Discussion started by: kmanivan82
3 Replies

5. Shell Programming and Scripting

Find and Replace Path in UNIX

Hi All, How can i find and replace the one path to another path with in the file. For Example: Search_path=/search/path replace_path=/replace/path I used the following command but not usefull, please help me regarding the same. sed 's_/search/path_/replace/path_' file_name >... (6 Replies)
Discussion started by: nsyed.dw
6 Replies

6. Shell Programming and Scripting

sed find and replace command not working

Hi, Am trying to replace a character '-' with 'O' in position 289 in my file but am not success with below command. sed 's/^\(.\{289\}\)-/\1O/' filename sed: 0602-404 Function s/^\(.\{289\}\)-/\1O/ cannot be parsed. Thanks in Advance Sara Video tutorial on how to use code tags in The... (9 Replies)
Discussion started by: Sara183
9 Replies

7. Shell Programming and Scripting

sed command to find and replace

Hello All, I need a sed command to find and replace below text in multiple files in a directory. Original Text :- "$SCRIPT_PATH/files" Replace with :- "$RESOURCE_FILE" Thank you in advance !!! Regards, Anand Shah (1 Reply)
Discussion started by: anand.shah
1 Replies

8. Shell Programming and Scripting

Character Find and replace in Unix or Perl

Hi, I am stuck with an problem and want some help, what i want to do is There is a directory name temp which include file named t1.txt, t2,txt, t3.txt and so on. These files contains data, but there are some bad character also that is % present in the files , I want to write the script... (13 Replies)
Discussion started by: parthmittal2007
13 Replies

9. Shell Programming and Scripting

find and replace command

Hi, i used to do on soalris box but in linux box i am not able to do advice is appreciated uname -a Linux intranet 2.4.20-pre3 #1 Tue May 6 17:55:35 IST 2008 i686 unknown $ find /usr/local/ -type f | xargs perl -pi -e 's/172.16.1.14/172.16.1.27/g' Can't remove /usr/local/bin/dbhome:... (1 Reply)
Discussion started by: prakash.gr
1 Replies

10. UNIX for Dummies Questions & Answers

find and replace command in one line using one command

Hi, I have a entry in the file as ::BSNL GUJARAT::India::OUT::NAT::REWEL::POSTPAID::919426199995 if u see this, i have the delimiter as :: , all i want is to replace "::" as ":" so how to do that.. pls help thanks (10 Replies)
Discussion started by: vasikaran
10 Replies
Login or Register to Ask a Question