mac_online
mac_online

Reputation: 370

Filter records based on Text in Unix

I'm trying to extract all the records that matches the text "IN" in the 10th field from this file.

i tried but it's not giving me the accurate results. Any help provided here would be highly appreciated.

awk '$10 == "IN" {print $0}'

input_file: my input file

A1|A2|A3|A4|A5|A6|A7|A8|A9|PK|A11|A13|A14|A15|A16|A17|A18
1|2|3|4|5|6|7|8|9|IN|11|12|13|14|15|16|17|18
AW|BW|CQ|AA|AR|AF|RR|AKL|ASD|US|PP|BN|TY|OL|Q3|M8|I7|V6
AR|BR|CR|A8|AN|AQ|RU|A11|A13|IN|P9P|B0N|T2Y|O4L|Q43|M88|I71|V16

output_file: my output should be

1|2|3|4|5|6|7|8|9|IN|11|12|13|14|15|16|17|18
AR|BR|CR|A8|AN|AQ|RU|A11|A13|IN|P9P|B0N|T2Y|O4L|Q43|M88|I71|V16

all the records that matched "IN" in the 10th field should be filtered.

Upvotes: 0

Views: 590

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133528

Since you haven't mentioned the field separator in awk code so by default it makes space as field separator and your Input_file is | pipe delimited so let awk know you should set it up in code.

Could you please try following.

awk -F'|' '$10=="IN"'  Input_file

Explanation: Adding explanation for above code too.

awk -F'|' '         ##Setting field separator as |(pipe) for all lines of Input_file.
$10=="IN"           ##Checking condition if 10th field is equal to IN here if yes then print the current line.
'  Input_file       ##Mentioning Input_file name here.

Upvotes: 2

Related Questions