檔案迴圈輸入 - Linux

By Faithe
at 2013-12-12T19:17
at 2013-12-12T19:17
Table of Contents
我們可以用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
--
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
--
Tags:
Linux
All Comments

By Christine
at 2013-12-15T12:22
at 2013-12-15T12:22

By Una
at 2013-12-16T20:35
at 2013-12-16T20:35

By Carol
at 2013-12-18T00:08
at 2013-12-18T00:08

By Liam
at 2013-12-20T02:57
at 2013-12-20T02:57

By Anonymous
at 2013-12-20T20:36
at 2013-12-20T20:36

By Ina
at 2013-12-24T15:48
at 2013-12-24T15:48

By Ingrid
at 2013-12-26T22:11
at 2013-12-26T22:11
Related Posts
Android adb Tab補齊

By Andy
at 2013-12-11T21:46
at 2013-12-11T21:46
無法Ping Domain (已爬文)

By Mason
at 2013-12-11T16:50
at 2013-12-11T16:50
compile linux kernel code問題

By Thomas
at 2013-12-10T20:37
at 2013-12-10T20:37
如何遠端部署/啟動 Apache + Tomcat

By Puput
at 2013-12-10T18:23
at 2013-12-10T18:23
請問一個記憶體問題

By Wallis
at 2013-12-10T16:01
at 2013-12-10T16:01