linux系統中如何將一行數據轉換為一列數據


 

1、測試數據 測試1

[root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10

 

2、測試2

[root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 [root@centos7 test2]# cat a.txt | xargs -n 1
01
02
03
04
05
06
07
08
09
10

 

3、測試3

[root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 [root@centos7 test2]# cat a.txt | sed 's/ /\n/g'
01
02
03
04
05
06
07
08
09
10

 

4、測試4

[root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 [root@centos7 test2]# cat a.txt | tr " " "\n"
01
02
03
04
05
06
07
08
09
10

 

5、測試5

[root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 [root@centos7 test2]# awk BEGIN{RS=EOF}'{gsub(" ","\n");print}' a.txt 01
02
03
04
05
06
07
08
09
10

 

6、測試6

[root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 [root@centos7 test2]# awk '{for(i = 1; i <= NF; i++) {printf("%s\n",$i)}}' a.txt 01
02
03
04
05
06
07
08
09
10

 

7、測試7

[root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 [root@centos7 test2]# awk 'BEGIN{RS=" ";ORS="\n"}{print}' a.txt | head -n -1
01
02
03
04
05
06
07
08
09
10

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM