看板 Linux 關於我們 聯絡資訊
我們可以用Loop輸出, 並在script外面把stdout 轉向到檔案上: vi test.sh #!/bin/bash for i in {1..10} do echo "this is output" done chmod +x test.sh; ./test.sh >out; cat out 但我找書找來找去卻沒有方法讓script可以從一個檔案一行一行輸入並處理 假設有個檔案長這樣 #1 aa 1 2 3 bb 2 3 4 #2 dd 33 5 1 df 5 61 2 #3 fe 3 5 1 gg 64 12 12 有沒有人知道要怎麼弄一個script讓這檔案一行一行輸入處理? #!/bin/bash for (某i行檔案; i++) do line=第i行檔案內容 if (line第一個字==#); then .............. fi done -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.240.159.112
lantw44:一次讀一行可以用 read 12/12 19:56
DreamLoser:是能夠用read 但永遠只能read第一行 12/12 20:05
DreamLoser:不曉得有沒有方法能夠shift行數去read進去 12/12 20:06
CaptainH:while read line; do echo "$line"; done < file 12/12 20:36
losepacific:i=0;while read -r line[${i}];do i=$(( $i + 1 )) 12/12 21:00
losepacific:done < 檔案 12/12 21:01
losepacific:echo ${line[3]} | grep -o '^.' 12/12 21:01
johu:for a in `cat file` 12/13 08:28