简体   繁体   English

AWK按字符过滤数据

[英]AWK filter data by characters

A data set like below: 数据集如下:

07021201180934221NJL B2018   12X 15253                                                                                                               030C       000000.299
07021201180934231NSL B2018   12X 15253                                                                                                               030C        00000.014
07021201180941061NNL B2018                                                                                                                           030C       000000.288

Questions are: 问题是:

  1. The characters in the first string "120118" means date "ddmmyy", how could I filter rows according to date characters using awk? 第一个字符串“ 120118”中的字符表示日期“ ddmmyy”,如何使用awk根据日期字符过滤行?

  2. The characters in first string "NJL" or "NSL" or "NNL" means data type, what awk command to filter lines according to those three characters? 第一个字符串“ NJL”或“ NSL”或“ NNL”中的字符表示数据类型,请问用哪种awk命令根据这三个字符过滤行?

  3. The third column could be some description like "12X 15253" or empty, how could I filter data out if the column is empty? 第三列可能是一些描述,例如“ 12X 15253”或为空,如果该列为空,如何过滤数据?

Thanks in advance! 提前致谢!

该脚本具有所有条件

$ awk 'substr($1,5,6)==120118 && substr($1,length($1)-2)=="NNL" && $3$4==""' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM