linux - bash : inexplicable behavior sed -


i wrote quite simple bash script :

#!/bin/bash  nline=$(awk '/text_to_parse/{ print nr; exit }' testfile.xml) echo "line = $nline" sed -e "${nline}s/.*/new text/" < testfile.xml echo  cat testfile.xml  exit 0 

the execution returns :

line = 8 <test>     <name>first test</name>     <version>1.0</version>             <command>new text</command> </test>  <test>     <name>first test</name>     <version>1.0</version>             <command>text_to_parse</command> </test> 

the modification never applied. file can modified ..

 -rwxrwxrwx 1 root root  290 jan  1 00:23 testfile.xml 

your whole script should rewritten 1 command:

sed -i 's/.*text_to_parse.*/new text/' testfile.xml cat testfile.xml 

you'll need provide param -i in seds.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -