我有兩個文件input1.txt和input2.txt。匹配文件中的字符串並打印下一列
input1.txt具有以下細節:
abcd.net
bcad.net
cagh.net
degh.net
usna.net
input2.txt具有以下細節:
abcd.net 169.254.0.2
bcad.net 169.254.0.3
cagh.net 169.254.0.4
us-1212-qwe.net 169.254.232.50
us-cisco.net 10.120.2.3
degh.net 169.254.0.5
usna.net 169.254.0.6
ab1234.net 169.254.0.7
catorr.net 169.254.0.8
我需要在 「input1.txt」 中列出的服務器對應的IP細節從文件 「input2.txt」
輸出應該是這樣的:
abcd.net 169.254.0.2
bcad.net 169.254.0.3
cagh.net 169.254.0.4
degh.net 169.254.0.5
usna.net 169.254.0.6
我的代碼如下所示無法正常工作。請幫忙。
for i in `cat input1.txt`; do more input2.txt | grep -w "^$i"; done
每當你在shell中編寫一個循環來操縱文本時,你有錯誤的方法。請參閱http://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice。 –