简体   繁体   中英

Regular expression using grep to match the beginning and end of a string

I have to find running file which will have format like:

"Throughput_Monitor_20141211T111311.792-0-V4.4.6_UE_9"

I am using regular expression as:

ps aux | grep -i [^Throughput_Monitor_]*[UE_9]$

but I am getting not only the above file but couple of other files. Could anyone help me find the regular expression? I am not sure where I am making mistake.

thanks

ps aux | grep -i ^Throughput_Monitor_.*?UE_9$

猜猜这应该为您工作。

You should not use anchors in command line since your command line may have some additional stuff.

You can use:

ps aux | grep -Ei '\bThroughput_Monitor_.*UE_9\b'

Better to use pgrep if you have it:

pgrep -ifl 'Throughput_Monitor_.*UE_9'

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