Thanks!! for your quick solution it worked with this kind of pattern.........(had to replace nawk by awk....it seems nawk is not supported on my linux)
But it slipped my mind :o to mention that I have to first search for YYYYMMDD like pattern meaning it is not certain that it'll be at the 3rd position only. It could be anywhere in the string like
instead of 99_*_YYYYMMDD_SRC.txt.tar.gz
it could be 99_*_SRC_YYYYMMDD.txt.tar.gz
or YYYYMMDD_99_*_SRC.txt.tar.gz
I mean to say it could be anywhere in the string.....sorry for the confusion
I think I have an additional requirement involving extraction of YYYYMMDD parttern, however what you assumed about this being a mnemonic for data/time data is now true. Can you help me out again?
For e.g.
i/p1: 45_*_20111019_SRC.txt.tar.gz -> o/p: 20111019
i/p2: 201110192359_45_*_SRC.txt.tar.gz -> o/p: 201110192359
i/p3: 45_*_SRC_2011101923.txt.tar.gz -> o/p: 2011101923
I attempted the below code:
echo 45_*_20111019_SRC.txt.tar.gz | sed 's/.....\(.\{8\}\)\(.*\)/\1/'
but I know this is in vain because it's too much tied up with the length of the string & the pattern length!!
-dips
you have to assume a minimum length of numbers to determine if it's a date or not. As your dates may differ in length, I assumed the minimum length of 8 - \{8,\} . Notice the trailing comma in the spec. From man ed :
* An RE followed by:
\{m\}
Matches exactly m occurrences of the character matched by
the RE.
\{m,\}
Matches at least m occurrences of the character matched by
the RE.
\{m,n\}
Matches any number of occurrences of the character matched
by the RE from m to n inclusive.