Advertisement
homer512

paste 6 POSIX sed

May 3rd, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.55 KB | None | 0 0
  1. #!/bin/sed -f
  2.  
  3. # Concatenates up to 6 lines with ' '
  4. #
  5. #i.e.: '1\n2\n3\n4\n5\n\6\n7\n\8\n9\n10\n11\n12\n13\n14\n'
  6. # becomes '1 2 3 4 5 6\n7 8 9 10 11 12\n13 14\n'
  7.  
  8.  
  9. : restart
  10. # if less than 5 embedded newlines, i.e. < 6 fields in pattern space
  11. /\(.*\n\)\{5\}/ ! {
  12.     # if last line, print
  13.     $ b print
  14.     # otherwise, append next line to pattern space and repeat
  15.     N
  16.     b restart
  17. }
  18. # 6 fields in pattern or all available, even when less
  19. : print
  20. # replace embedded line ends with desired field separator
  21. y/\n/ /
  22. # then end cycle with output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement