Subham Tripathi
Subham Tripathi

Reputation: 2733

Strange Behaviour of [SED] when put in shell script

when i am doing this

sed 1s/#text_to_be_replaced#/replacement_string/ filename

then the output is as expected but when i put it in a shell file and do this

lineNumber=1
sed $lineNumbers/#text_to_be_replaced#/replacement_string/ filename

then it doesn't work as expected the replacement_string gets inserted one line above the text_to_be_replaced. Why is it happening ?

Upvotes: 0

Views: 35

Answers (1)

Arjun Mathew Dan
Arjun Mathew Dan

Reputation: 5298

It should be:

sed "${lineNumber}s/text_to_be_replaced/replacement_string/" filename

Upvotes: 4

Related Questions