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?
A shame that the previous perl answers are so long. Here are two perl one-liners:
On older versions of perl (without "say"), you may use this:
Ruby versions for comparison:
Python in the same spirit as the above awk (4 lines):
Python 1-liner (omitting the pipe to it which is identical):
Another Perl 5 version:
Just for comparison, here's a few Perl scripts to do it (TMTOWTDI, after all). A rather functional style:
We could also do it closer to the AWK script:
I've run out of ways to do it, so if any other clever Perlers come up with another method, feel free to add it.
you could also just use tr:
echo "abc edf xyz rfg yeg udh" | tr ' ' '\n'