Linux

選擇文件中具有相同字元串模式的行

  • December 22, 2021

假設我有以下內容file.txt

asiub
sj
abq
b aia
ainp oo
test = 123d
sub ,.
aiba 87ab
test = 129szs bq
test = aqua
ayqvq 133s 

我只想列印file.txt包含字元串的行test =

想要的output.txt

test = 123d
test = 129szs bq
test = aqua

有什麼建議嗎?

謝謝

grep "test =" file.txt > output.txt

要僅在行首匹配字元串,請使用

grep "^test =" file.txt > output.txt

引用自:https://unix.stackexchange.com/questions/683471