开发者

help parsing values using perl regular expression

I'm stuck trying to figure out the perl regex to extract the following values: (the /home/mail/dump dirs will always be the same). Thanks.

abc

123456

This is the output:

drwxr-xr-x   开发者_C百科- mail_hd mail_users          0 2011-03-26 20:12 /home/mail/dump/abc
drwxr-xr-x   - mail_hd mail_users          0 2011-04-15 09:10 /home/mail/dump/123456


Maybe use split and basename, instead.


This is similar to this.

Split on "/" and get the last item

awk -F"/" '{print $NF}' file

Ruby(1.9+) (similar for Perl)

$ ruby -ne 'print $_.sub(/.*\//,"")' file
abc
123456

$ ruby -F"/" -ane 'print $F[-1]' file
abc
123456


The following perl regex will give just the characters after the final forward slash.

s=.*/==

Example:

$ echo 'wxr-xr-x   - mail_hd mail_users          0 2011-03-16 18:46 /home/mail/dump/abc' | perl -pe 's=.*/=='
abc


Maybe this is usefull, should return what you need.

if ($subject =~ m!/home/mail/dump/(.*)$!) {
    $result = $1;
} else {
    $result = "";
}

it matches everything after /home/mail/dump/ until end of line

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜