2012-09-11 38 views
0

一個文件行通常我用雖然條件貓一行

cat filename|while read line; do 
echo $line 

這工作得很好......但我想與附加了一個條件做到這一點。

cat filename|while i=2 read line; do 
echo $line 

現在我知道不會工作,但我怎麼能附加一個條件呢?

+2

遍歷文件的正確方法是'while read line;做...;完成 chepner

回答

0

這是HP,SOL & RHEL我的最終工作version..works。

cat $NASFILE|while [[ $NFS2 != "Completed" ]] && read line; do 
3

您需要連接的條件,像這樣:

while ((i == 2)) && read line; do 
+0

這是測試在ksh93(Mac OS X,山獅) – Petesh

+0

裏面((...))美元符號是不必要的。 – chepner

+0

確實,編輯以反映 – Petesh