
我想要的就是像這樣指定一定數量的行lineNumberIs=3
,並告訴讀取時從第三行開始或從什麼行號開始,並在之後獲取行以稍後在獲取的行上執行一些命令
類似的東西
while read line from $lineNumberIs
do
**some commands not just echo nor printing on the screen**
done < $dataFile
答案1
答案2
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Please execute $0 with linestoskip parameter"
exit 0
fi
linestoskip=$1
Counter=0
dataFile='/etc/fstab'
while read line
do
if [ $Counter -ge $linestoskip ]; then
echo $line
fi
Counter=`expr $Counter + 1`
done < $dataFile
該腳本需要跳過的行數作為參數。你可以在內部 if 條件下做任何你想做的事情。
答案3
非常簡單的解決方案 -
tail -n +K filename
其中 K = 要讀取檔案的行號。這將從第 K 行開始讀取檔案到末尾。