简体   繁体   English

如何使用 linux shell 脚本在文件中找到这种模式?

[英]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.

相关问题 如何使用 Linux 命令找到我的 shell 版本? - How can I find my shell version using a Linux command? 如何在没有find的情况下在linux shell脚本中根据日期查找和删除文件? - How can I find and delete files based on date in a linux shell script without find? 使用Linux脚本根据文件名模式查找和移动文件 - find and move files based on file name pattern using linux script 如何编写一个 shell 脚本文件可以在 Linux 中运行脚本 - How to write a shell script file that can run a script in Linux 如何找出适合由 shell 脚本解析的 linux 机器的总物理内存 (RAM)? - How can I find out the total physical memory (RAM) of my linux box suitable to be parsed by a shell script? 如何使用 java 或 shell 脚本查找 unix/linux 系统信息? - How to find unix/linux sytem info using java or shell script? 如何使用shell脚本查找Linux Distribution名称? - How to find Linux Distribution name using shell script? 我想使用shell脚本linux在文件中写一行 - I want to write a single line in file using shell script linux 在Linux Shell脚本上需要帮助以查找字符串模式 - Need help on Linux Shell Script to find a pattern of strings 我如何使用Shell脚本在Linux中获得所有用户及其授权? - How can i get all the users and their authorize_key in linux using shell script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM