![](/img/trans.png)
[英]How to match only odd occurrences of a character at the end of the line using grep
[英]How to grep a shell variable to match end of line?
如何在行尾匹配bash變量?
下面的代碼可以最后完成一個數字:
grep '[0-9]$'
但就我而言,數字是一個變量。 我希望像
grep '{$i}$'
其中$ i是我的變量,可以工作,但無濟於事。 我嘗試了幾種單/雙逗號組合,但到目前為止沒有成功。
提前致謝。
您可以使用以下grep
:
grep "$i\$" file
要么:
grep $i'$' file
您必須在外殼程序中使用"double quoting"
進行變量擴展。使用以下命令:
grep "$i\$" file
使用單引號使$作為行尾使用。 如果還要使用某些變量來grep,請使用雙引號和單引號,如下所示:
grep“ $ var”'$'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.