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/ /\n/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 " " "\n"
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(" ", "\n"); 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\n", $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 = "\n"} {print}' a.txt
3
s
g
a
e
f
k
n
y

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

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。