[英]how to grep an exact string which has a variable
我有一個如下文件,我只想搜索"this[*]: world * seconds"
,其中*
表示變量
sudo cat log | grep "world" | grep this -m1
Apr 26 04:19:12 : SESSION = 111, from_remote_host = , USER = root, PWD = /root, CMD = 2018-04-26 04:19:12 sudo cat log | grep "world" | grep this -m10
Apr 26 04:18:45 xxxx aaaaaaaaaaaaaaaaaa: SESSION = 101675, from_remote_host = jjjjjjj, USER = root, PWD = /root, CMD = 2018-04-26 04:18:45 sudo cat log | grep "world" | grep this -m1
Apr 26 04:11:54 xxxx this[98461]: world 29.93 seconds
Apr 26 03:41:50 xxxx this[77844]: world 18.87 seconds
Apr 26 03:11:36 xxxx this[58682]: world 18.60 seconds
Apr 26 02:42:29 xxxx this[43432]: world 34.56 seconds
我認為這條線會做你想要的:
grep -E 'this\[[0-9]+\]: world [0-9.]+ seconds' file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.