Hi,
I want to only replace one pattern in specified line of one file.The file may contains many lines,the line containing the pattern 'http:' is:
ServerResourceURL DN=I want to replace nwp001--->pwd003, only in the line containing the 'http:' pattern, and leave other lines which contains nwp001 unchanged/un-replaced,i.e., the above line will be this:
ServerResourceURL DN=So after replacement,The file will be updated, all other lines(including those contain 'nwp001' but not contain 'http:') will remain unchanged, only this line with 'http:' is replaced by pwd003.
Thanks very much! It is blocking my testing!!
Suppose the file to be updated is named "file_forsed"
I use this statement, but always report syntax error,
I don't know how to fix this issue??
#!/bin/ksh
item=./file_forsed
crtfile=`basename ${item}`
old_host="nwp001"
new_host="pwd003"
cp ${item} ./${crtfile}.tmp.$$
cat ./${crtfile}.tmp.$$ | awk '/http:/ { Line=$0; Line1=$(echo $Line | sed "s/${old_host}/${new_host}/g";next} {print $0 }' > ./tmp_${crtfile}
rm -f ./${crtfile}.tmp.$$ 2>> ./elog
exit 0
Thanks again!
I want to only replace one pattern in specified line of one file.The file may contains many lines,the line containing the pattern 'http:' is:
ServerResourceURL DN=I want to replace nwp001--->pwd003, only in the line containing the 'http:' pattern, and leave other lines which contains nwp001 unchanged/un-replaced,i.e., the above line will be this:
ServerResourceURL DN=So after replacement,The file will be updated, all other lines(including those contain 'nwp001' but not contain 'http:') will remain unchanged, only this line with 'http:' is replaced by pwd003.
Thanks very much! It is blocking my testing!!
Suppose the file to be updated is named "file_forsed"
I use this statement, but always report syntax error,
I don't know how to fix this issue??
#!/bin/ksh
item=./file_forsed
crtfile=`basename ${item}`
old_host="nwp001"
new_host="pwd003"
cp ${item} ./${crtfile}.tmp.$$
cat ./${crtfile}.tmp.$$ | awk '/http:/ { Line=$0; Line1=$(echo $Line | sed "s/${old_host}/${new_host}/g";next} {print $0 }' > ./tmp_${crtfile}
rm -f ./${crtfile}.tmp.$$ 2>> ./elog
exit 0
Thanks again!