我有2個文件:使用awk的結果作爲參數來grep一個文件?
1 - userfile.txt與格式=>鮑勃:bobhash
2 - => bobhash passfile.txt與格式:bobpass
我想要得到的bobpass給出的用戶「bob」,如果可能,用單行命令。
所以,到目前爲止,我正在做這樣的:
awk -F: '$1="bob" {print $2}' userfile.txt
# output: bobhash
# copy by using mouse
cat passfile.txt | grep 'bobhash' | awk -F: '{print $2}'
#output: bobpass
我不知道是否有更好的方法來做到這一點。我已經試過grep -f
,但沒有運氣。
是的,只需使用一個awk命令而不是多個awks + grep。您的問題包括簡潔,可測試的樣本輸入和預期輸出,您將獲得幫助。 –