![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Try...
Code:
sed -e "s!$indir!$newdir!g" $fname > temp |
|
#3
|
|||
|
|||
|
Thanks!
it does the job.
|
|
#4
|
|||
|
|||
|
Quote:
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! |
|
#5
|
||||
|
||||
|
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. Vino |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
||||
|
||||
|
sed 's/\(.*\),\(..\)\(..\)\(..\)\(..\)/\1,\2,\3,\4,\5/' input_file
|
||||
| Google The UNIX and Linux Forums |