简体   繁体   中英

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). What i want to find is string followed by 4 numbers separated by comma and ended with semicolon.

Sample input:

READ 1h, 2h, 3h, 4h;

Here READ is a string.

您可以使用 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 -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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM