=D# sample input: $ ls | head -11 Desktop Documents Downloads Library Movies Music Pictures Public Sites bin cgi-bin # 21-character perl script: $ ls | head -11 | perl -pe 's{$/}{ } unless($.%2)' Desktop Documents Downloads Library Movies Music Pictures Public Sites bin cgi-bin
(update: That version replaces the default line termination with a space. If you just want to delete the line termination (first char of line 3 immediately follows last char of line 2, etc), take the space out of the replacement block in the regex, making it a 20-character script.)
Another update: oops! just noticed that I'm not supposed to output the first line, so I either have to lengthen the perl script, or else lengthen the command line:
(The latter allows me to shorten the perl script even more, and so would be my personal favorite.)# using a longer perl script: $ ls | head -11 | perl -pe '$_="" if($.==1);s{$/}{ } unless($.%2)' Documents Downloads Library Movies Music Pictures Public Sites bin cgi-bin # using a longer command line: $ ls | head -11 | tail +2 | perl -pe 's{$/}{ } if($.%2)' Documents Downloads Library Movies Music Pictures Public Sites bin cgi-bin
In reply to Re: When every 2 lines of a file (sans first) should be 1...
by graff
in thread When every 2 lines of a file (sans first) should be 1...
by metaperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |