Tag Archives: CZX

Pattern Match & Extract from a string

By karumudi7

Hi,

I have long string in 2nd field, as shown below:

Code:


REF1 | CLESCLJSCSHSCSMSCSNSCSRSCUDSCUFSCU7SCV1SCWPSCXGPDBACAPA0DHDPDMESED6
REF2 | SBR4PCBFPCDRSCSCG3SCHEBSCKNSCKPSCLLSCMCZXTNPCVFPCV6P4KL0DMDSDSASEWG


I have a group of fixed patterns which can occur in these long strings & only one pattern will come for one record, I will maintain all possible patterns in a file called Patterns.txt:

Code:

APA
APC
DFH
CZX


Eg: for the first record, APA occured and for second rec CZX occured and both are occured at differnt positions.

Expected output:

Code:


REF1 | APA
REF2 | CZX


Thanks

Source: FULL ARTICLE at The UNIX and Linux Forums