I have some data on a single line like below
abc edf xyz rfg yeg udh
I want to present the data as below
abc
xyz
yeg
edf
rfg
udh
so that alternate fields are printed with newline separated. Are there any one liners for this?
I have some data on a single line like below
abc edf xyz rfg yeg udh
I want to present the data as below
abc
xyz
yeg
edf
rfg
udh
so that alternate fields are printed with newline separated. Are there any one liners for this?
Another Perl solution:
You could even condense it into a real one-liner:
For newlines, i leave it to you to do yourself.
My attempt in haskell:
Here is yet another way, using Bash, to manually rearrange words in a line - with previous conversion to an array:
Cheers!
The following
awk
script can do it:Here's the too-literal, non-scalable, ultra-short
awk
version:Slightly longer (two more characters), using nested loops (prints an extra newline at the end):
Doesn't print an extra newline:
For comparison, paxdiablo's version with all unnecessary characters removed (1, 9 or 11 more characters):
Here's an all-Bash version: