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]") ;"}}'

猜你喜欢

转载自lhg4study.iteye.com/blog/1924612