[Solved] making each word of a line to a separate line

Hi,

I have a line which has n number of words with separated by space.

I wanted to make each word as a separate line.

for example,

i have a file that has line like

i am a good boy

i want the output like,

i
am
a 
good
boy
 

Please suggest.

tr " " "\n" < file
1 Like

And another one:

printf '%s\n' $(< infile)
1 Like

And another one...

xargs -n1 < infile

@radoulov, that would allow the shell to do unintended filename expansion, no?

2 Likes

Though I'd use the "tr" in post #2, yet another one ...

awk 'BEGIN {RS=" ";ORS="\n"} {print $0}' infile
1 Like

Keep 'm coming :slight_smile:

awk '{$1=$1}1' OFS="\n" infile
grep -Eo '[^ \t]+' infile
sed 's/[ \t][ \t]*/\
/g' infile
1 Like

Yes. I should have mentioned it, thanks!

1 Like
xargs -n 1 echo < filename
1 Like

Many Thanks to all. It is workine fine. :slight_smile: