linux系统中如何将一行数据变为一列

1、测试数据

[root@centos79 test]# cat a.txt
3 s g a e f k n y

2、xargs

[root@centos79 test]# cat a.txt
3 s g a e f k n y
[root@centos79 test]# cat a.txt | xargs -n 1
3
s
g
a
e
f
k
n
y

3、sed

[root@centos79 test]# cat a.txt
3 s g a e f k n y
[root@centos79 test]# cat a.txt | sed 's/ /
/g'
3
s
g
a
e
f
k
n
y

4、tr

[root@centos79 test]# cat a.txt
3 s g a e f k n y
[root@centos79 test]# cat a.txt | tr " " "
"
3
s
g
a
e
f
k
n
y

5、awk

[root@centos79 test]# cat a.txt
3 s g a e f k n y
[root@centos79 test]# awk '{gsub(" ", "
"); print}' a.txt
3
s
g
a
e
f
k
n
y

6、awk

[root@centos79 test]# cat a.txt
3 s g a e f k n y
[root@centos79 test]# awk '{for(i = 1; i <= NF; i++){printf("%s
", $i)}}' a.txt
3
s
g
a
e
f
k
n
y

7、awk

[root@centos79 test]# cat a.txt
3 s g a e f k n y
[root@centos79 test]# awk 'BEGIN{RS = " "; ORS = "
"} {print}' a.txt
3
s
g
a
e
f
k
n
y

[root@centos79 test]# awk 'BEGIN{RS = " "; ORS = "
"} {print}' a.txt | sed '$d'
3
s
g
a
e
f
k
n
y
原文地址:https://www.cnblogs.com/liujiaxin2018/p/15056771.html