Extract partial string from path.

Hi all,

i've a string
$DIR=/u/user/NDE/TEST_LOGS/20110622_000005_TEST_11_HD_120/HD/TEST_11_HD_120/hd-12

i need to extract string from 2011.... i.e i need it as 20110622_000005_TEST_11_HD_120 as matched string, and in turn i need to split values 20110622_000005_TEST_11_HD_120 into two. i.e 20110622_000005 in one variable and rest into other.

string, may start with any thing, like.. /a/b/c/d/201106....., but it always has time stamp, i.e 20110622_00 ... etc.. and end with /HD

please help..

Thanks ,
ASAK

Oops...

Can you start your solution with something like:

$ echo /u/user/NDE/TEST_LOGS/20110622_000005_TEST_11_HD_120/HD/TEST_11_HD_120/hd-12 | tr "/" "\n" | grep "^[0-9]\{8\}"
20110622_000005_TEST_11_HD_120

$ echo "/u/user/NDE/TEST_LOGS/20110622_000005_TEST_11_HD_120/HD/TEST_11_HD_120/hd-12" | awk -F"/" ' { print $6 } ' | sed 's,^,var1=,g;s,_,; var2=,2'

var1=20110622_000005; var2=TEST_11_HD_120

$

Hi all,

In perl how to do it?? i need it in perl.... please help.. using regular expression

Regards,
ASAK

echo $DIR | perl -nle '/(\d+_\d+)([^\/]+)\/HD/; print $1'
echo $DIR | perl -nle '/(\d+_\d+)([^\/]+)\/HD/; print $2'
1 Like

HI bartus11,

Thankyou very much, this is what exactly i wanted...

Regards,
Asak

---------- Post updated at 08:53 AM ---------- Previous update was at 08:52 AM ----------

Hi All,

Thanks for your reply,

Regards,
Asak