The UNIX and Linux Forums  

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 here.

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-26-2005
Registered User
 

Join Date: Aug 2005
Posts: 4
Red face sed help!

the follwing is the script I used to replace directory name in a file. ( I used b-shell)

fname=test1
echo "input original directory"
read indir
echo "input new directory"
read newdir
sed -e 's/'$indir'/'$newdir'/g' $fname > temp

if $indir and $newdir don't include any special character, just string including letter and number only, it works. otherwise, there is error information showed up.

for example, when being asked to input indir and new dir, I input "sin04b\/cp06" and "sin05b\/cp05", the error information is:
sed: 0602-404 Function s/sin04b/cp06/sin05b/cp05/g cannot be parsed.

if I input "sed -d 's/sin04b\/cp06/sin05\/cp05/g' test1 > temp" in command line, it works. I have no idea why it doesn't work in script but works in command line.

Thanks a lot.
Reply With Quote
Forum Sponsor
  #2  
Old 08-27-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Try...
Code:
sed -e "s!$indir!$newdir!g" $fname > temp
Reply With Quote
  #3  
Old 08-27-2005
Registered User
 

Join Date: Aug 2005
Posts: 4
Thanks!

it does the job.
Reply With Quote
  #4  
Old 09-01-2005
Registered User
 

Join Date: Aug 2005
Posts: 12
Quote:
Originally Posted by Ygor
Try...
Code:
sed -e "s!$indir!$newdir!g" $fname > temp
Ygor?

How does this work? are the "!" replacing "/"?

I was getting the same errors as the poster, replaced "/" with "!" and now my sed script is working as needed.

Thanks!

This truly is a helpful Forum!
Reply With Quote
  #5  
Old 09-01-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,681
From info sed

Code:
The `s' Command
===============

   The syntax of the `s' (as in substitute) command is
`s/REGEXP/REPLACEMENT/FLAGS'.  The `/' characters may be uniformly
replaced by any other single character within any given `s' command.
The `/' character (or whatever other character is used in its stead)
can appear in the REGEXP or REPLACEMENT only if it is preceded by a `\'
character.
I think this is a privilege for the users of GNU sed. Not sure about the other flavours.

Vino
Reply With Quote
  #6  
Old 04-25-2007
Registered User
 

Join Date: Apr 2007
Posts: 4
Pls help for me!

I need this text change

example:

FFFFFF00,852813FE
FFFFFF01,251D2829
FFFFFF02,BDB8A846
FFFFFF03,3D089F7C

after sed:

FFFFFF00,85,28,13,FE
FFFFFF01,25,1D,28,29
FFFFFF02,BD,B8,A8,46
FFFFFF03,3D,08,9F,7C
Reply With Quote
  #7  
Old 04-25-2007
Shell_Life's Avatar
Registered User
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
sed 's/\(.*\),\(..\)\(..\)\(..\)\(..\)/\1,\2,\3,\4,\5/' input_file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0