0

I have a file with foll format:

key1
123
key2
345

I want to get it as:

key1 123
key2 345

I am trying a mix of seds , grep etc but not quite getting what I want. Any suggestions . I think deleteing "\n" on every odd row would also do the trick but can get that to work .

codeObserver
  • 6,521
  • 16
  • 76
  • 121

2 Answers2

6

This is a job for paste

paste -d " " - - < filename
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
3

I think this might work for you:

echo -e "key1\n123\nkey2\n456" | sed 'N;s/\n/ /'
potong
  • 55,640
  • 6
  • 51
  • 83
  • The `N` command appends a newline, then the next line to the current line. The `s/\n/ /` replaces the newline (`\n`) with a space. – potong Dec 09 '11 at 08:13