开发者

extracting the values using grep

Sample String : a.txt

Reading:RG1:+ /user/reading/Monday:12
Reading:RG1:- /user/**/Friday:12
Reading:RG1:- /user/**/*.txt:12
Reading:RG1:- /user/tet/**/*.txt:1开发者_开发技巧2

I am looking to extract the string

after + or - what ever the string i want it 

using :

cat a.txt | grep RG1|grep '+'| cut -d':' -f3| cut -d'+' -f2 |sed -e 's/ //

I am getting /user/reading/Monday

But i amlooking

/user/reading/Monday:12


Use egrep -o:

$ egrep -o '/user/reading/[A-Z][a-z]+day:[0-9]+' a.txt
/user/reading/Monday:12
/user/reading/Friday:12

Edit: for your new example, use something like

$ egrep -o '/user/[^ ]*:[0-9]+' a.txt
/user/reading/Monday:12
/user/**/Friday:12
/user/**/*.txt:12
/user/tet/**/*.txt:12

Assuming no spaces in your paths.


To fix your command, use -f3- because you want everything from the 3rd field to the end of the line.

cat a.txt | grep RG1|grep '+'| cut -d':' -f3-| cut -d'+' -f2 |sed -e 's/ //'


$ grep -Po '(?<=[-+] ).*' a.txt
/user/reading/Monday:12
/user/**/Friday:12
/user/**/*.txt:12
/user/tet/**/*.txt:12

Change the characters with the square brackets to change which lines you select.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜