歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> awk處理文件小實踐

awk處理文件小實踐

日期:2017/3/1 15:28:30   编辑:關於Linux
awk處理文件小實踐 文件中包含3個字段(已排好序):舉例如下: news news_1 1234556 news news_1 1234557 news news_2 1234558 news news_2 1234559 sport sport_1 2234555 sport sprot_1 2234558 sport sport_2 2234556 sport sport_2 2234557 1根據第一個列,將第一列相同的寫入同一個文件 awk '{print $2,$3 > $1}' file 2、切割成不同文件後,構造sql 想要如下效果(select * from news_1 where id in(1234556,123447)) awk '{id[$1]=id[$1]?(id[$1]","$2):$2;}END{for(i in id){print "select* from "i"_post where id in("id[i]") ;"}}'
Copyright © Linux教程網 All Rights Reserved