Shejo284 Shejo284 - 1 year ago 91
Bash Question

sed cannot find file

I'm using sed in a bash script to change some variable values. These variables are mixture of different types and include also some special characters:

sed -i -e "s/NPROC=[^,]*,/NPROC=$NPROC/" \
-e "s/TSTEP=[^,]*,/TSTEP=$TSTEP/" \
-e "s/NCEXTR=[^,]*,/NCEXTR=$NCEXTR/" \
-e "s/NVXTR2=[^,]*,/NVXTR2=$NVXTR2/" \
-e "s/NVEXTR=[^,]*,/NVEXTR=$NVEXTR/" \
-e "s/NVEXTRAGB=[^,]*,/$NVEXTRAGB/" \
-e "s/NVEXTR2GB=[^,]*,/$NVEXTR2GB/" \
-e "s/NFPLEV=[^,]*,/NFPLEV=$NFPLEV/" \
-e "s/CNMEXP=[^,]*,/CNMEXP=\"${EXPID}\"/" \
-e "s/LFPOS=[^,]*,/NFPOS=2/" \
-e "s/NLAT=[^,]*,/NLAT=$NLAT/" \
-e "s/NLON=[^,]*,/NLON=$NLON/" \
+ sed -i -e 's/NPROC=[^,]*,/NPROC=10/' ' '
sed: can't read : No such file or directory

However, I keep getting the error that the file $NAMELIST cannot be found. The file does exits in the same directory and there is no error in the name. Adding the fullpath doesn't help either. So I'm wondering what is wrong in this sed command.

Answer Source

You have a space after the first backslash. Instead of escaping the newline to continue the command, you're escaping the space, so it thinks the name of the file to edit is a single space.

Make sure that the backslashes are the last character on every line.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download