extracting the values using grep

Reading:RG1:+ /user/reading-2/Monday:12
Reading:RG1:- /user/**/Friday:12
Reading:RG1:- /user/**/*.txt:12
Reading:RG1:- /user/tet-23/**/*.txt:12
Reading:RG2:+ /user/reading-2/Monday:12
Reading:RG2:- /user/**/Friday:12
Reading:RG2:- /user/**/*.txt:12
Reading:RG2:- /user/tet-23/**/*.txt:12

我试过这个:
目录A.txt grep rg1 grep'-'cut-d':'-f3-cut-d'-'-f2 sed-e's///
这不起作用,因为它将提取错误的路径,因为+的一些还具有-
如何重新审视这个问题

最佳答案

试试这个:

egrep "^[^:]*:RG1:-" a.txt | cut -d: -f3 | cut -b3-

样本运行:
$ cat a.txt
Reading:RG1:+ /user/reading-2/Monday:12
Reading:RG1:- /user/**/Friday:12
Reading:RG1:- /user/**/*.txt:12
Reading:RG1:- /user/tet-23/**/*.txt:12
Reading:RG2:- /user/tet-23/**/*.txt:12
Reading:RG2:+ /user/reading-2/Monday:12
$ egrep "^[^:]*:RG1:-" a.txt | cut -d: -f3 | cut -b3-
/user/**/Friday
/user/**/*.txt
/user/tet-23/**/*.txt

"^[^:]*:RG1:-"的意思是“从任何事情开始,但是:零次或多次,然后是a:,然后是aRG1,最后是-

关于linux - 使用grep提取值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4085949/

10-09 14:54