Devoloper250
Devoloper250

Reputation: 813

Regular expression in Bash shell

I have unix code which reads files from directory which matches predefined format and moves them to different directory for processing. Below is the existing working pattern and examples.

[A-Za-z]{5}.[A-Za-z]{2}.INPUT.[0-9]*(.TXT|.txt)$

Old file Example1 :- STATS.WE.INPUT.20140227.TXT

Old file Example1 :- STATS.WE.INPUT.20150245654.TXT

New file pattern has been changed and below is the sample file name and format I have tried.

New file Example :- STATS.WE.INPUT.20140227.A2345.465789765.TXT

New file Example2:- STATS.WE.INPUT.20140227.2345.465789765.TXT

New file Example3:- STATS.WE.INPUT.20140227.2345.46578976534234.TXT

[A-Za-z]{5}.[A-Za-z]{2}.INPUT.[0-9]*.[A-Za-Z0-9]*.[0-9]*(.TXT|.txt)$

Please let me know what need to be changed in above expression.

Upvotes: 0

Views: 244

Answers (1)

kaldoran
kaldoran

Reputation: 855

here is the answer :

^[A-Za-z]{5}\.[A-Za-z]{2}\.INPUT.[0-9]*\.[A-Za-z0-9]+\.[0-9]+(.TX‌​T|.txt)$

Just from the all pattern I had this part : \.[A-Za-z0-9]+\.[0-9]+ in order to match .A2345.465789765 for example.

Upvotes: 1

Related Questions