Xuhang
Xuhang

Reputation: 495

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?

  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?

  3. The third column could be some description like "12X 15253" or empty, how could I filter data out if the column is empty?

Thanks in advance!

Upvotes: 0

Views: 1000

Answers (1)

karakfa
karakfa

Reputation: 67507

this script has all the conditions

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

Upvotes: 2

Related Questions