regex 使用正则表达式过滤掉每行中的特定字符串

20jt8wwn  于 2023-04-22  发布在  其他
关注(0)|答案(1)|浏览(106)

我想过滤掉每一行的突出字符串

已更改:[hostname 1] =〉(item='uid':1000,“woth”:False,'mtime':1679196024.843057,'inode':1139800,'isgid':False,'size':11745724295,‘罗斯’:False,'isuid':False,'isreg':True,'pw_name':'jira','gid':1000,'ischr':False,'wusr':True,'xth':False,'rusr':True,'nlink':1,'issock':False,'rgrp':True,'gr_name':'jira','path':'/mnt/nfs/jira/export/2023-Mar-18--1900.zip'
已更改:[hostname 2] =〉(item='uid':1000,“woth”:False,'mtime':1679588444.705138,'inode':1175380,'isgid':False,'size':11834841900,‘罗斯’:False,'isuid':False,'isreg':True,'pw_name':'jira','gid':1000,'ischr':False,'wusr':True,'xth':False,'rusr':True,'nlink':1,'issock':False,'rgrp':True,'gr_name':'jira','path':'/mnt/nfs/jira/export/2023-Mar-23--0801.zip'
已更改:[hostname 3] =〉(item='uid':11668,“woth”:False,'mtime':1679825130.0182097,'inode':201355653,'isgid':False,'size':20971707,‘罗斯’:False,'isuid':False,'isreg':True,'pw_name':'confluence','gid':11668,'ischr':False,'wusr':True,'xth':False,'rusr':True,'nlink':1,'issock':False,'rgrp':True,'gr_name':'confluence','path':'/confluence/home/logs/atlassian-confluence.log.5',' xusr ':False,'time':1679486655.01409,'isdir':False,'ctime':1681368284.8271954,'isblk':False,'xgrp':False,'dev':64768,'wgrp':False,'isfifo':False,'mode':'0640',' islnk':False})
已更改:[hostname 4] =〉(item='uid':11667,“woth”:False,'mtime':1680248205.0145996,'inode':100784645,'isgid':False,'size':20971526,‘罗斯’:False,'isuid':False,'isreg':True,'pw_name':'confluence','gid':11667,'ischr':False,'wusr':True,'xth':False,'rusr':True,'nlink':1,'issock':False,'rgrp':True,'gr_name':'confluence','path':'/confluence/home/logs/atlassian-confluence.log.4',' xusr ':False,'time':1679735745.013214,'isdir':False,'ctime':1681520175.011039,'isblk':False,'xgrp':False,'dev':64768,'wgrp':False,'isfifo':False,'mode':'0640',' islnk':False})

我可以过滤掉一些字符串,但它也包括changed:'path:'之间的文本。我如何过滤掉changed: [hostname1] =>'path': (.*),只有:

egrep -o  "changed: \[(.*)\] =>(.*) 'path': '([^,]*)'"

我也试过:

egrep -o  "changed: \[(.*)\] =>'([^('jira|confluence,)']*)' 'path': '([^,]*)'"
0pizxfdo

0pizxfdo1#

您可以使用alternative(|)来不匹配以下内容:

changed: \[([^\]]+)\] =>|'path': '([^']*)'

还请注意,我将greedy (.*)更改为([^\]]+)(除了]之外的任何值),这在值中还有]的情况下更可靠。
Demo
我还建议使用Perl语法运行它,因此使用grep -oP而不是egrep -o
或者,不要用egrep转义]

egrep -o "changed: \[([^]]+)\] =>|'path': '([^']*)'

相关问题