1

I have file

head file1
12 0 
9 3 
12 0 
12 0 
12 0 
12 0 
7 5 

I want to convert the second column into row

head desired

12
0
9
3
12
0
12
0
12
0
7
5

Thanks

Anna1364
  • 1,026

5 Answers5

7

An easy job for tr:

$ cat input | tr ' ' '\n'
12
0
9
3
12
0
12
0
12
0
12
0
7
5
DopeGhoti
  • 76,081
3

You can use awk on this.

 awk '{for(i=1;i<=NF;i++) printf "%s\n",$i}' input.txt
2

Some other options:

fmt -0 file1

Or:

xargs -n 1 < file1
Zombo
  • 1
  • 5
  • 44
  • 63
1
tr -s '[:blank:]' '\n' < file

or

awk 'BEGIN{RS="[ \t\n]+"} 1' file
steeldriver
  • 81,074
1

Using xargs:

xargs -n1 < <(head input)

Or you could take advantage of the shells word splitting:

printf '%s\n' $(head input)
jesse_b
  • 37,005