|
Daniel
|
 |
« 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
|
 |
« 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
|
 |
« 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
|
 |
« 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
|
 |
« 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: 2203
|
 |
« 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
|
 |
« 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
|
 |
« 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
|
 |
« 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
|
 |
« Reply #10 on: June 11, 2009, 10:41:48 am » |
|
Try using all double quotations.
|
|
|
|
|
Logged
|
|
|
|
|
Daniel
|
 |
« 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
|
|
|
|