linux 下處理大文件


 

1head tail more

2、先把大文件進行分割 split

split 參數:
-a, --suffix-length=N   指定輸出文件名的后綴,默認為2個
-b, --bytes=SIZE        指定輸出文件的字節數
-C, --line-bytes=SIZE  每一輸出檔中,單行的最大 byte-d, --numeric-suffixes  使用數字代替字母做后綴
-l, --lines=NUMBER    NUMBER 值為每一輸出檔的列數大小
   
例:
[root@10.10.90.97 sh]# split -b 1024 -a 3 push.sh
[root@10.10.90.97 sh]# ls 
push.sh xaaa  xaab  xaac  xaad  xaae  xaaf
使用-a參數指定文件后綴名的個數為3

[root@10.10.90.97 sh]# split -b 1024 push.sh push_  
[root@10.10.90.97 sh]# ls
push_aa  push_ab  push_ac  push_ad  push_ae  push_af    push.sh
-b參數指定輸出文件的大小為1024字節,push_指定輸出文件的前綴代替默認的x 

[root@10.10.90.97 sh]# split -b 1024 -d push.sh 
[root@10.10.90.97 sh]# ls
push.sh x00  x01  x02  x03  x04  x05
-d參數設置輸出文件的后綴為數字,默認的為字符  

[root@10.10.90.97 sh]# split -l 5 push.sh 
[root@10.10.90.97 sh]# ls
push.sh  xaa  xac  xae  xag  xai  xak  xam  xao  xaq  xas  xau  xaw  xay  xba
xab  xad  xaf  xah  xaj  xal  xan  xap  xar  xat  xav  xax  xaz
-l指定輸出穩定的行數為5 

附:合並文件命令(會自動按后綴排序連接):
    cat small_files* > large_file

3sed 按行進行處理
    總行數:wc -l 文件名

    sed -n '1,1024(文件總行數)p' filename;#依次輸出文件的每一行

4awk 一次讀取文件中的一行
    awk '{print;}' employee.txt  #依次輸出文件的每一行

 

 

 


免責聲明!

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



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