Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 1
    Wow, the combination of paste and tr is perfect for this problem! So concise! I can't use the sed and cut trick however, because it is not actually the last field I want to sort on. Commented Dec 16, 2015 at 8:06
  • 2
    In the event that you want more lines concatenated and not hundreds of - you can use xargs -n5 <file instead of paste, where 5 is the number of lines to be concatenated. Commented Dec 16, 2015 at 9:21
  • 2
    @User112638726 - that's an entirely different thing. that's an exec of /bin/echo for every five input lines. if you don't want to type out hundreds of - dashes something like: set "" - -; while [ "$#" -lt 100 ]; set "$@$@"; done; shift "$(($#-100))"; paste "$@" or eval paste "$(printf %100s|sed 's/./- /g')" Commented Dec 16, 2015 at 9:26
  • 1
    @User112638726 - that's a good point, but they don't do so in the loop. in general - in my experience - it is far better to do a little more work to prepare a loop than it is to otherwise do the work during the loop. the loop, in this case, is the processing of the input file. in my suggestions the extra stuff only happens the one time to build an argument list for paste to afterward take it from there, but with xargs you cut up the argument list and distribute it to all of the different echo invocations. i dunno about your comment -thought it was weird too. i saw it for a second. Commented Dec 16, 2015 at 9:36
  • 2
    fair enough :) IMO it is more apparent what the xargs is doing though and is neater, so if resources are abundant then i personally think it is the better choice. Also the original i posted was wrong and split on all [[:space:]] characters. The command should have been xargs -d'\n' -n5 < file Commented Dec 16, 2015 at 9:42