我試圖檢索{{
和| translate
之間的文本。在mac上使用grep提取特殊字符之間的字符串
輸入:TESTFILE.TXT
views/range.html: <button type="button" class="btn" ng-click="setRange(7 * 24 * 3600 * 1000)">{{ '7 days' | translate }}</button>
views/widget.html: <span class="state">{{phase}}/2</span> {{titles[phase-1] | translate}}
views/directives/widget.html: <button class="btn" ng-disabled="selectedWidgets.length === 0" ng-click="phase = 2">{{ 'Next' | translate }}</button>
預期結果:
'7 days'
titles[phase-1]
'Next'
到目前爲止已經試過:
grep "translate" | grep -o "'[^']*'" testfile.txt
#results
'7 days'
'Next'
grep '{\{\(.*\)|\translate%\1%' testfile.txt
#results
grep: invalid repetition count(s)
awk -F '{{|translate' '{print $2}' testfile.txt
#results
'7 days' |
phase}}/2</span>
'Next' |
我在MacOS塞拉利昂,版本10.12.4這樣做。謝謝!
如果你可以安裝GNU的grep,它會很容易地得到所需要的結果 – RomanPerekhrest
您能在答案提供反饋下面如果它幫助你? – Inian