LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2011, 03:27 PM   #1
Sha_unix
Member
 
Registered: Sep 2011
Posts: 46

Rep: Reputation: Disabled
Question Command to find in each file and replace one or two words


Hi
i have few files called

asdf.sh
qwer.sh
hxhc.sh
.
.
.etc

cat asdf.sh
PROGHOME=/home/progress
find / -name /user/folder/

now i want to replace /home to /mine and /folder to /fold in all *.sh files in single shot as i dont want to get into each file and modify... pleaes let me know if any command such.
 
Old 11-18-2011, 03:59 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,945

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by Sha_unix View Post
Hi
i have few files called

asdf.sh
qwer.sh
hxhc.sh
.
.
.etc

cat asdf.sh
PROGHOME=/home/progress
find / -name /user/folder/

now i want to replace /home to /mine and /folder to /fold in all *.sh files in single shot as i dont want to get into each file and modify... pleaes let me know if any command such.
Very similar to your other thread:
http://www.linuxquestions.org/questi...e-shot-913500/

Replace the sed delete command in that script with a substitute command. Try that?
 
Old 11-18-2011, 04:08 PM   #3
Sha_unix
Member
 
Registered: Sep 2011
Posts: 46

Original Poster
Rep: Reputation: Disabled
But my replacement has / (forwardslash) those slashes are making me trouble. i used \(backslash) but may be some where i am doing wrong it seems, not able to get desired output.

Code:
sed '\/emc/reale/apps/pseudo/rsdm.pf /s\//emc_str/reale/apps/pseudo/rsdm_str.pf /g' vendors2.sh usersecg.sh
 
Old 11-19-2011, 05:54 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,945

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by Sha_unix View Post
But my replacement has / (forwardslash) those slashes are making me trouble. i used \(backslash) but may be some where i am doing wrong it seems, not able to get desired output.

Code:
sed '\/emc/reale/apps/pseudo/rsdm.pf /s\//emc_str/reale/apps/pseudo/rsdm_str.pf /g' vendors2.sh usersecg.sh
You have to put a backslash in front of EVERY forwardslash, not just one.
 
Old 11-19-2011, 07:18 PM   #5
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 211

Rep: Reputation: 67
sed allows arbitrary regex delimiters. Your '\/' told it to use forward slash as a delimiter. The man page doesn't point out (but the info node does) that the s command uses the first following character as a delimiter: sed s,a,b,g is equivalent to tr a b.
 
Old 11-22-2011, 02:30 PM   #6
Sha_unix
Member
 
Registered: Sep 2011
Posts: 46

Original Poster
Rep: Reputation: Disabled
i tried using every time backslash didnt workout

code:
sed '\/emc/reale\/apps\/pseudo\/rsdm.pf /s\/\/emc_str\/reale\/apps\/pseudo\/rsdm_str.pf /g' vendors2.sh usersecg.sh

[/code]

i dont see anything on right like "Add to Reputation" button, on the left of the post.
 
Old 11-22-2011, 02:36 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,945

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
[QUOTE=Sha_unix;4530866]i tried using every time backslash didnt workout
Code:
sed '\/emc/reale\/apps\/pseudo\/rsdm.pf /s\/\/emc_str\/reale\/apps\/pseudo\/rsdm_str.pf /g' vendors2.sh usersecg.sh
...because you're not calling SED correctly for a substitution. Quick Google search for "sed substitution examples", yields:
http://www.thegeekstuff.com/2009/10/...tion-examples/

You're not telling it to substitute at the beginning.
Code:
sed 's/\/emc\/reale\/apps\/pseudo\/rsdm.pf/\/emc_str\/reale\/apps\/pseudo\/rsdm_str.pf/g' <ONE filename>
See your previous thread that I referenced here. Sed will still only take one file at a time, unless you script it, which is what your last thread had already written.
Quote:
i dont see anything on right like "Add to Reputation" button, on the left of the post.
The little "scales" icon...when hovered over, tells you that's what it is.
 
1 members found this post helpful.
Old 11-22-2011, 02:44 PM   #8
Sha_unix
Member
 
Registered: Sep 2011
Posts: 46

Original Poster
Rep: Reputation: Disabled
Thank you. its working now. and i posted this reply as helpful, is that what it adds to reputation i guess.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace a string in a file using perl command from bash script koundinya749 Programming 5 02-15-2011 05:52 PM
[SOLVED] command to find/replace in a text file? sneakyimp Linux - Newbie 17 02-15-2011 01:30 AM
Find several different words and replace with one using sed. Techno Guy Linux - Newbie 18 07-06-2009 08:16 AM
Linux command to find and replace string within text file chips11 Linux - Newbie 5 11-24-2008 03:25 PM
command line edit -- global find/replace on text file w/o going into vi car182 Linux - Newbie 4 05-25-2006 06:42 PM


All times are GMT -5. The time now is 02:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration