[英]Bash Script: write all but first three lines of stdin to file
我正在編寫一個bash腳本,它一度使用nslookup
來解析循環中的某些名稱。 它的輸出看起來像這樣:
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: example.org
Address: 93.184.216.34
我想刪除前三行,而不必先將輸出寫入文件。 我嘗試使用tail
,但無法從STDIN讀取它。
nslookup "${name}" \
| tail +2 -
這會嘗試將+2
作為文件讀取: tail: cannot open '+2' for reading: No such file or directory
如何管道nslookup的輸出以刪除前三行,以便稍后將所有內容寫入文件,如下所示:
while read name; do
nslookup "${name}" \
| remove-three-lines \
>> file.out
done <"${nameFile}"
從第4行開始輸出(忽略前3行):
nslookup "${name}" | tail -n +4
或者awk:
nslookup "${name}" | awk 'NR>3'
或者sed:
nslookup "${name}" | sed '1,3d'
那這個呢:
while read name; do
echo $(nslookup "${name}" | tail -2) >> file.out
done <"${nameFile}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.