VectorLinux

Please login or register.

Login with username, password and session length
Advanced search  

News:

Visit our home page for VL info. For support and documentation, visit the Vector Linux Knowledge Center or search the Knowledge Center and this Forum using the search box above.

Author Topic: "sed" question  (Read 4081 times)

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
"sed" question
« on: May 13, 2009, 11: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
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« Reply #1 on: May 13, 2009, 08: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
Re: "sed" question
« Reply #2 on: May 14, 2009, 03:33:24 am »

Very interested. I need something just like that.
Thanks
Bruce
Logged

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« Reply #3 on: June 10, 2009, 04: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: 4132
Re: "sed" question
« Reply #4 on: June 10, 2009, 06: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
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« Reply #5 on: June 11, 2009, 06: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: 2317
Re: "sed" question
« Reply #6 on: June 11, 2009, 08: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
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« Reply #7 on: June 11, 2009, 08: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
Re: "sed" question
« Reply #8 on: June 11, 2009, 08: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
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« Reply #9 on: June 11, 2009, 08: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: 4132
Re: "sed" question
« Reply #10 on: June 11, 2009, 11:41:48 am »

Try using all double quotations.
Logged

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« Reply #11 on: June 11, 2009, 01: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