vendredi 7 octobre 2022

Using awk, how do I match pattern and variants?

I've been struggling with this for a while in regex testers but what came up as a correct regex pattern actually failed. I've got a large file, tab delimited, with numerous types of data. I want to print a specific column, with the characters XYZ, and it's subsequent values.

In the specific column I'm interested in I have values like:

XYZ

ABCDE

XYZ/WORDS

XYZ/ABCDE

ABFE

XYZ

regex tester that was successful was something like:

XYZ(.....)*

It obviously fails when implemented as:

awk '{if ($1=="XYZ(......)*") print$0}'

What regex character do I use to denote that I want everything after the backslash(/), including the original pattern (XYZ)?

Specifically, I want to be able to capture all instances of XYZ, and print the other columns that go along with them (hence the print$0). Specifically, capture these values:

XYZ 

XYZ/WORDS

XYZ/ABCDE

Thank you

Aucun commentaire:

Enregistrer un commentaire