Please support VectorLinux!

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

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
"sed" question
« 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.
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, 07:18:20 pm »
Never mind, I figured it out. The solution was: sed 's/text/'$variable'/g' file.txt    if anybody is interested.
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, 02:33:24 am »
Very interested. I need something just like that.
Thanks
Bruce

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« 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?
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: 4073
Re: "sed" question
« 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.

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« 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.
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: 2299
Re: "sed" question
« Reply #6 on: June 11, 2009, 07:33:43 am »
try following nightflier suggestion but using double quotes instead
"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, 07:48:36 am »
rbistolfi: can you elaborate on that?
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, 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

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« Reply #9 on: June 11, 2009, 07:57:31 am »
It doesn't recognize the variables that way either.
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: 4073
Re: "sed" question
« Reply #10 on: June 11, 2009, 10:41:48 am »
Try using all double quotations.

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
Re: "sed" question
« 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.
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