Home > Net >  AWK to look up Text
AWK to look up Text

Time:06-25

I want to be able to fetch people's whose number starts with 93 and were registered in 2021 from this file:

<ID>;<Name>;<Driving License ID>;<Contact>;<Bank ID>;<Balanca>;<Registration Date>
ID234580880;John;L1234567;961112223;234580880;150;2020-03-07
ID205202021;Elisa;L3453333;918564555;205202021;120;2021-04-06
ID223679890;Daniel;L1237774;938764333;223679890;100;2021-05-02
ID124563568;Peter;L6744567;938998994;124563568;50;2020-01-03
ID785645332;Mary;L9847366;964765322;785645332;90;2021-01-03
ID134563888;Sofia ;L3938889;916590890;134563888;30;2022-05-19

I have come up with this answer using awk:

awk '/;93/ && /2021-/' drivers.txt

But if by chance, anyone has a Bank ID that also starts with 93, as shown below, how could I get still get the data?

<ID>;<Name>;<Driving License ID>;<Contact>;<Bank ID>;<Balanca>;<Registration Date>
ID234580880;John;L1234567;961112223;234580880;150;2020-03-07
ID205202021;Elisa;L3453333;918564555;205202021;120;2021-04-06
ID223679890;Daniel;L1237774;938764333;223679890;100;2021-05-02
ID124563568;Peter;L6744567;938998994;124563568;50;2020-01-03
ID935645332;Mary;L9847366;964765322;935645332;90;2021-01-03
ID134563888;Sofia ;L3938889;916590890;134563888;30;2022-05-19

CodePudding user response:

You can do regex matching on specific fields:

awk -F';' '$4 ~ /^93/ && $7 ~ /^2021/'
  • Related