1.使用read命令读取一行数据 while read myline do echo "LINE:"$myline done < datafile.txt 2.使用read命令读取一行数据 cat datafile.txt | while read myline do echo "LINE:"$myline done 3.#读取一行数据 cat datafile.txt | while myline=$(line) do echo "LINE:&qu
写法一: #!/bin/bash while read line do echo $line done < file(待读取的文件) 写法二: #!/bin/bash cat file(待读取的文件) | while read line do echo $line done 写法三: for line in `cat file(待读取的文件)` do echo $line done 说明:for逐行读和while逐行读是有区别的,如: $ cat file aaaa bbbb cccc dddd
Shell脚本,执行解释速度快.代码简单易于理解.在shell代码编写过程中,经常会用到读取文件内容. 写法一: ---------------------------------------------------------------------------- #!/bin/bash while read line do echo $line done < file(待读取的文件) ------------------------------------------
可以通过改变当前文件的偏移量来实现文件的读取 -offsetInFile获取文件当前的位移量 -seekToFileOffset:(NSUInteger)length设置文件当前的位移量 -readDataOfLength:(NSUInteger)length随机读取文件内容的字节数 -seekToEndOfFile将文件跳到结尾 // // main.m // 04-NSFileHandle随机读取 // // Created by ma c on 15/8/24. // Copyright
写法一: ---------------------------------------------------------------------------- #!/bin/bash while read line do echo $line done < filename(待读取的文件) ---------------------------------------------------------------------------- 写法二: --------------------
1.使用while #!/bin/bash while read line do echo $line done < file.txt #!/bin/bash cat file.txt | while read line do echo $line done 2.使用for for line in `cat file.txt` do echo $line done