VectorLinux
August 23, 2014, 10:57:37 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: "sed" question  (Read 3413 times)
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« on: May 13, 2009, 10:59:17 am »

I am trying to use the sed command in a script. I need to make the command something like this:

sed -i 's,text-to-replace,variable-to-replace-it-with,g' file-to-do-this-in.txt

I have tried things like: sed -i 's,text,'$variable',g' file.txt and it says there is an incomplete 's' command. Can anybody help? Please ask for clarification if needed.
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« Reply #1 on: May 13, 2009, 07:18:20 pm »

Never mind, I figured it out. The solution was: sed 's/text/'$variable'/g' file.txt    if anybody is interested.
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
no2thesame
Packager
Vectorite
****
Posts: 136


« Reply #2 on: May 14, 2009, 02:33:24 am »

Very interested. I need something just like that.
Thanks
Bruce
Logged
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« Reply #3 on: June 10, 2009, 03:59:31 pm »

Ok, slightly different problem with sed. I need to do this:

sed -i 's|'$(grep 'text' /file to look in)'|'$(grep 'text' /different file to look in)'|g' /file to do this in

Whenever I try to run this command, it says "unterminated `s' command".
Help anyone?
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
nightflier
Administrator
Vectorian
*****
Posts: 4020



« Reply #4 on: June 10, 2009, 05:21:33 pm »

I think the problem is with your single quotation marks. The interpreter reads what's between the two first ones, as in:
sed -i 's|'
Try removing all single quotation marks except the first and last.
Logged
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« Reply #5 on: June 11, 2009, 05:49:19 am »

If I take away the single quotation marks around the variables, it doesn't recognize them as variables anymore. Just text.
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
rbistolfi
Packager
Vectorian
****
Posts: 2282


« Reply #6 on: June 11, 2009, 07:33:43 am »

try following nightflier suggestion but using double quotes instead
Logged

"There is a concept which corrupts and upsets all others. I refer not to Evil, whose limited realm is that of ethics; I refer to the infinite."
Jorge Luis Borges, Avatars of the Tortoise.

--
Jumalauta!!
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« Reply #7 on: June 11, 2009, 07:48:36 am »

rbistolfi: can you elaborate on that?
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
uelsk8s
Administrator
Vectorian
*****
Posts: 2504



« Reply #8 on: June 11, 2009, 07:53:03 am »

sed -i 's|"$(grep text /file to look in)"|"$(grep text /different file to look in)"|g' /file to do this in
Logged
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« Reply #9 on: June 11, 2009, 07:57:31 am »

It doesn't recognize the variables that way either.
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
nightflier
Administrator
Vectorian
*****
Posts: 4020



« Reply #10 on: June 11, 2009, 10:41:48 am »

Try using all double quotations.
Logged
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« Reply #11 on: June 11, 2009, 12:18:03 pm »

Nope, still doesn't work. It recognizes the variables but gives the "unterminated `s' command" error.
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!