[英]How can i find this pattern in file using linux shell script?
string Xh,Xh,Xh,Xh;
Here X can be any Hex number(upto 4 digit).这里 X 可以是任何十六进制数(最多 4 位)。 What i want to find is string followed by 4 numbers separated by comma and ended with semicolon.我想找到的是字符串后跟用逗号分隔的 4 个数字,并以分号结尾。
Sample input:样本输入:
READ 1h, 2h, 3h, 4h;
Here READ is a string.这里 READ 是一个字符串。
您可以使用 grep 找到它:
echo "string aFh, 09h, 4bh, FFh;" | grep -e "string \([a-fA-F0-9]\{2\}h\, \)\{3\}\([a-fA-F0-9]\{2\}h\;\)"
The below grep command will work as you expected.下面的 grep 命令将按您的预期工作。
grep -E "^([A-Za-z]+[0-9]{4}),([A-Za-z]+[0-9]{4}),([A-Za-z]+[0-9]{4}),([A-Za-z]+[0-9]{4})\\;$" grep -E "^([A-Za-z]+[0-9]{4}),([A-Za-z]+[0-9]{4}),([A-Za-z ]+[0-9]{4}),([A-Za-z]+[0-9]{4})\\;$"
It will match the string followed by 4 digits(without space between string and digit) and match the comma, up to 4 times like this and ended with semicolon line.它将匹配后跟4位数字的字符串(字符串和数字之间没有空格)并匹配逗号,最多4次,以分号行结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.