The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Help Urgent SanjayLinux Shell Programming and Scripting 4 10-29-2007 02:41 AM
Help me for AWK URGENT readycpbala Shell Programming and Scripting 2 02-22-2007 01:03 PM
URGENT,URGENT- Need help tape drive installation sriny UNIX for Advanced & Expert Users 3 11-16-2006 03:43 PM
URGENT---URGENT--No OK PROMPt after RSC CONFIG sriny SUN Solaris 7 10-29-2006 11:06 AM
Urgent !! desiondarun UNIX for Dummies Questions & Answers 1 08-08-2006 09:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-07-2008
katrvu katrvu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 25
Urgent Help With Sed

Hello,
I need to use sed to replace a word in file.
My command is this:
sed "s/word_to_replace/'"${INPUT}"'/1 filename

and because INPUT="~@#$%^&*()-_=+{}[]\|;:<>,./?"
and / is also the delimiter so I'm keep on getting error message
sed: command garbled: ...

any suggestions about how I might solve it?

THANK YOU VERY MUCH
  #2 (permalink)  
Old 02-07-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,762
That is a very odd replacement string...

It has every usable delimiter that sed will recognize. You can escape the / in the replacment string like this \/
  #3 (permalink)  
Old 02-07-2008
katrvu katrvu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 25
Quote:
Originally Posted by jim mcnamara View Post
That is a very odd replacement string...

It has every usable delimiter that sed will recognize. You can escape the / in the replacment string like this \/
However, I can not change what's in the string, because the string comes from a line in a file. and I cannot predict wat's in the file.
Other ideas?

thank you
  #4 (permalink)  
Old 02-07-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by katrvu View Post
Hello,
I need to use sed to replace a word in file.
My command is this:
sed "s/word_to_replace/'"${INPUT}"'/1 filename

and because INPUT="~@#$%^&*()-_=+{}[]\|;:<>,./?"
and / is also the delimiter so I'm keep on getting error message
sed: command garbled: ...

any suggestions about how I might solve it?

THANK YOU VERY MUCH
sed -e "sQword_to_replaceQ${INPUT}Q" -e "s/\(\^\)word_to_replace\(\*\)/\1\2/"
  #5 (permalink)  
Old 02-07-2008
katrvu katrvu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 25
Quote:
Originally Posted by shamrock View Post
sed -e "sQword_to_replaceQ${INPUT}Q" -e "s/\(\^\)word_to_replace\(\*\)/\1\2/"
after use it, I got a error message say:
syntax error near unexpected token '-_=+{}[]\|'
I couldn't find what I did wrong.

String is "~@#$%^&*()-_=+{}[]\|;:<>,./?"
  #6 (permalink)  
Old 02-07-2008
katrvu katrvu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 25
Thank you, it works great except it's giving me "~@#$%^&*()-_=+{}[]|;:<>,./?" instead of "~@#$%^&*()-_=+{}[]\|;:<>,./?" so \ is missing
do you have idea wat a better command might be?

THANK YOU
  #7 (permalink)  
Old 02-07-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by katrvu View Post
Thank you, it works great except it's giving me "~@#$%^&*()-_=+{}[]|;:<>,./?" instead of "~@#$%^&*()-_=+{}[]\|;:<>,./?" so \ is missing
do you have idea wat a better command might be?

THANK YOU
Which platform are you running this on? I tried it on AIX and it runs w/o a hiccup...does not lose the backslash character.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0