shell解析讀取檔案的每一行

2021-09-10 18:12:20 字數 412 閱讀 3027

shell 中讀取文字的並且

3、使用ifs讀檔案

說明:預設情況下ifs是空格,如果需要使用其它的需要重新賦值

檔案中每一行都是以:分割 且檔名稱 通過引數 $1 傳進來 讀取

其具體解析邏輯為一下

while ifs=:

read field type comment others

doif [ -z 「$comment」 ]

then

echo " $field $type"

else

echo " $field typ

ecom

ment

′type comment '

typeco

mmen

t′comment』 "

fidone < $1

shell讀取檔案每一行的方式

使用read命令讀取一行資料 while read myline doecho line myline done datafile.txt 使用read命令讀取一行資料 cat datafile.txt while read myline do echo line myline done 讀取一行資...

shell讀取檔案每一行的方式

1 使用read命令讀取一行資料 1 2 3 4 whileread myline do echo line myline done datafile.txt 2 使用read命令讀取一行資料 1 2 3 4 cat datafile.txt whileread myline do echo lin...

shell讀取檔案的每一行寫法

shell讀取檔案的每一行寫法一 bin bash while read line doecho line done filename 待讀取的檔案 寫法二 bin bash cat filename 待讀取的檔案 while read line doecho line done 寫法三 for l...