linux - Sed command giving unexpected result -


below shell script trying find meaning.

sed 's/19984 $/98400 /' | sed 's/19992 $/99200 /' 

i expect 19984 $ replaced 98400 , string passed next sed command replace 19992 $ 99200 .

but when executed script below sample input

echo "19984 $ need  replaced 98400  "| sed 's/19984 $/98400 /' | sed 's/19992 $/99200 /' 

i same string

"19984 $ need  replaced 98400" 

i hope missing here. please me. new shell scripts. in advance!

for sed, $ reserved character have escape (\$) parsed properly:

$ echo "19984 $ need  replaced 98400  "| sed 's/19984 \$/98400 /'  98400  need  replaced 98400 

all together:

$ echo "19984 $ need  replaced 98400  "| sed 's/19984 \$/98400 /' | sed 's/19992 \$/99200 /' 98400  need  replaced 98400 

so need keep is.

$ can mean lot of things:
- normal character.
- end of line.
- name of variable.

the way got code means second case: end of line:

$ echo "19984 " | sed 's/19984 $/98400 /' 98400 $ echo "19984 something" | sed 's/19984 $/98400 /' 19984 

so sed match cases in line ends 19984. otherwise won't match.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -