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
Post a Comment