I have the file with the following format:
(Type 1 data:1)
B
B
(Type 1 data:2)
B
B
B
(Type 1 data:3)
B
..
Now I want to reformat this file so that it looks like:
(Type 1 data:1) B B
(Type 1 data:2) B B B
(Type 1 data:3) B
…
My approach was to use perl regex in command line,
cat file | perl -pe 's/\n(B)/ $1/smg'
My reasoning was to replace the new line character with space.
but it doesn’t seem to work. can you please help me? Thanks
The -p reads a line at a time, so there is nothing after the “\n” to match with.
this does almost what you want but puts one extra newline at the beginning and loses the final newline.