linux - How to insert a new line between 2 specific characters -
is there anyway insert new lines in-between 2 specific sets of characters? want insert new line every time }{ occurs in text file, want new line inserted between 2 curly brackets. example }\n{
you can run
sed -i -e 's/}{/}\n{/g' filename.ext
where
sedstream editor program-ioption edit filefilename.extin place-emeans regular expression followss/}{/}\n{/gregular expression meaning find (g) instances of }{ in every line , replace them }\n{\nregex new line. if omitg, replace first occurrence of search pattern still in every line.
to test before committing changes file, omit -i option , print result in stdout.
example:
create file:
echo "first }{ last" > repltest.txt run
sed -e 's/}{/}\n{/g' repltest.txt prints following stdout:
first } { last to effect change in same file, use -i option.
to run against stdin instead of file, omit -i , filename in piped command after outputs stdin, example:
cat repltest.txt | sed -e 's/}{/}\n{/g' which same sed -e 's/}{/}\n{/g' repltest.txt
Comments
Post a Comment