0

How do you convert a file like this:

ghosts: [[8, 16]]
pacman: [3, 15]
ghosts: [[4, 26]]
pacman: [4,15]

to a file like this:

ghosts: [[8, 16]], pacman: [3, 15]
ghosts: [[4, 26]], pacman: [4,15]

with the sed command?

I tried sed -e 's/\npac/, pac/g' input_file and got no change as a result.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
Jose Pinho
  • 33
  • 1
  • 6
  • Possible duplicate of [How do I remove the line break from alternate lines in an ASCII file](https://stackoverflow.com/questions/45412782/how-do-i-remove-the-line-break-from-alternate-lines-in-an-ascii-file) – Mad Physicist Oct 29 '18 at 19:59
  • 1
    Possible duplicate of [How to merge every two lines into one from the command line?](https://stackoverflow.com/questions/9605232/how-to-merge-every-two-lines-into-one-from-the-command-line) – ghoti Oct 29 '18 at 20:36

2 Answers2

0

This might work for you (GNU sed):

 sed 'N;s/\n/, /' file

Append the next line to the current and replace the newline by a comma followed by a space.

potong
  • 55,640
  • 6
  • 51
  • 83
0

another awk

$ awk '{ORS=NR%2?", ":RS}1' file

ghosts: [[8, 16]], pacman: [3, 15]
ghosts: [[4, 26]], pacman: [4,15]

or, with pr

$ pr -2ats', ' file

this should be the shortest way!

karakfa
  • 66,216
  • 7
  • 41
  • 56