sed - apply changes in multiple files
Try:
sed -s -n -i '0,/<\/foo:bar>/p' *.txt
-s
tells sed to treat each file as separate.
Because we don't want sed
to quit until all the files are done, we change to just print from the beginning to <\/foo:bar>
and not print the rest of the lines. -n
tells sed not print unless we explicitly ask it to. The command 0,/<\/foo:bar>/p
tells sed to print any line in the range from the beginning of the file to the first line that matches <\/foo:bar>
.
The -s
option is not available for BSD/OSX sed.
To stop reading the files when </foo:bar>
is found:
With GNU awk
:
gawk -i inplace '{print}; $0 == "</foo:bar>" {nextfile}' ./*.txt
With perl
:
perl -ni -e 'print; close ARGV if $_ eq "</foo:bar>\n"' ./*.txt