0
Can someone provide a simple one-liner to remove certain line breaks?
In vim I use %s/,\n]/]/g
This should be possible with a very simple one-liner IMHO, but how?
0
Can someone provide a simple one-liner to remove certain line breaks?
In vim I use %s/,\n]/]/g
This should be possible with a very simple one-liner IMHO, but how?
1
This should work:
perl -e "$_ = join('', <>); s/,\n]/,]/g; print;" < input_file > output_file
aii, that's a long one-liner, the actual vim command is so simple ... – Bastl – 2012-02-10T13:34:59.597
1Who cares? It works... The problem actually is the file input (<>). I have to convert the resulting array read from the file to a single line to process ($_ = join('', <>);) because file is splitted precisely by "\n". If anyone knows how to read a file in one single scalar, I'd be glad to modify it into something shorter. – m0skit0 – 2012-02-10T13:40:14.817
1*** If anyone knows how to read a file in one single scalar local $/ = undef;$string = <FILE>; – Yordan Georgiev – 2012-11-05T19:41:54.390
I learned it in the meantime, but thanks anyway :) – m0skit0 – 2012-11-05T22:45:28.300
1
This might work for you:
sed ':a;$!{N;ba};s/,\n]/]/g' file
or this:
sed 'N;s/,\n]/]/;P;D' file
0
perl -p -i.bak -e 's#to_find\n\n#to_replace#g' *.c
First remove newlines, then use sed.
But now everything is on one long line ? – Bastl – 2012-02-09T09:31:23.673
4"Certain linebreaks"? Which ones? – m0skit0 – 2012-02-09T09:40:37.890
those that occur in the pattern, i.e. surrounded by , and ] – Bastl – 2012-02-10T12:01:50.257
I can post an answer using Perl if you're interested. – m0skit0 – 2012-02-10T12:07:22.043
yes, pls, anything is appreciated, though perl is not at all my favourite ... :-) – Bastl – 2012-02-10T12:14:02.177