Reference: http://saiyaren.iteye.com/blog/1943207 1. Shell 读取文件和写文件 for line in $(<top30000.url.utf-8.http_server_front_hphp.txt); do tmp_port=8080; for((i=0;i<=7;i++));do echo ${line/192\.168\.12\.63/192\.168\.12\.63:$tmp_port} >>top3000
写法一: #!/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(待读取的文件) ------------------------------------------
环境 csh 说明 通常我们需要使用使用shell脚本处理一些事务,每次调用shell都需要添加参数. 如果重复调用多次这个shell脚本,我们可以将参数存入指定文件,循环得到参数. shell脚本(auto_run) #!/bin/csh -f #set list file of parameter set parameterlst = "$1" #loop execute run set n=`wc -l <$parameterlst` set i=1 while ($i &
写法一: ---------------------------------------------------------------------------- #!/bin/bash while read line do echo $line done < filename(待读取的文件) ---------------------------------------------------------------------------- 写法二: --------------------
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 content=`cat test.txt` echo "begin" for i in $content do echo $i done 读取前10行 test.txt 读取后10行 test.txt 读取第5行 sed -n "5,1p" test.txt 读取5到10行 ,10p" test.txt
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