天天看點

awk處理資料awk處理資料

awk處理資料

原始資料

  • 檔案名test.txt
  • 說明
    • 文本資料量形如下面的資料,資料量多的情況下excel不友善處理
    • 主要目的是通過第四列【手機号(0~9)】尾号将一個txt檔案拆分為10個檔案
L3020072600409325|BMAY1617|60100965888885|15035688731|1|20200801000000|20991231235959|heal02|20200726104846|20200726104846|2|20200801000000
L3020072200926044|BMAY1617|60100963277362|13834588453|1|20200801000000|20991231235959|aggsvD|20200722183930|20200722183930|2|20200801000000
           

核心處理語句

  • cat test.txt |awk -F '|' -va='|' '$4%10==0 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_0.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==1 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_1.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==2 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_2.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==3 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_3.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==4 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_4.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==5 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_5.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==6 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_6.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==7 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_7.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==8 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_8.txt
  • cat test.txt |awk -F '|' -va='|' '$4%10==9 {print $1a$2a$3a$4a$5a$6a$7a$8a$9a$10a$11a$12}' >>order_9.txt

指令解析

  • awk處理資料awk處理資料
awk