[英]How can I extract a substring from a matching line in a file?
I use: 我用:
cat display.txt | sed -e 's/...\(.*\).../\1/g'
to get string between("..."). 得到之间的字符串(“ ...”)。 But, it gives me this result which is full content of the file. 但是,它给了我这个结果,它是文件的全部内容。 How can I extract just "hhgggeeee"
from this? 如何从中提取"hhgggeeee"
?
= New Index: 98:4F:EE:06:0B:03 (BR/EDR,UART,hci0)
[hci0] 0.595705 > ACL Data RX: Handle 12 flags 0x02 dlen 19
[hci0] 11.420307 Channel: 64 len 15 [PSM 0 mode 0] {chan 0}
1b ef 17 68 68 67 67 67 65 65 65 65 0d 0a 8f
...hhgggeeee... > HCI Event: Mode Change (0x14) plen 6 [hci0] 11.923905
Status: Success (0x00) Handle: 12 Mode: Active (0x00)
Interval: 0.000 msec (0x0000)
You can use a perl
one liner for this: 您可以为此使用perl
一种衬垫:
perl -lne 'print $1 if /^\.\.\.(.*)\.\.\./' display.txt
For your file, it outputs: 对于您的文件,它输出:
hhgggeeee
You can use a sed command. 您可以使用sed命令。 Try the below command. 请尝试以下命令。
cat dis.txt|sed -n 's/\.\.\.\([^\.]\+\)\.\.\..*/\1/gp'
Or use can use the grep command also. 或者使用也可以使用grep命令。
cat dis.txt|grep -o '\.\.\.\([^\.]\+\)\.\.\.'
The both are gives the same output. 两者都给出相同的输出。 The output is 输出是
hhgggeeee
$ sed -n 's/.*\.\{3\}\(.*\)\.\{3\}.*/\1/p' file
hhgggeeee
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.