1.使用for循环 for line in `cat filename` do echo $line done 2.使用for循环 for line in $(cat filename) do echo $line done 3.使用while循环 while read -r line do echo $line done < filename…
有一个日志文件为: # cat data.log 需要提取出里面的数据,写shell脚本实现这个功能: #!/bin/bash OLD=$IFS IFS=$'\n' for entry in $(cat /home/users/data.log) do echo "Values in $entry is" IFS=' ' for value in $entry: do echo " $value" done done IFS=OLD 其中IFS变一个环境变量,作为l…
shell脚本实现读取一个文件中的某一列,并进行循环处理 1) for循环 #!bin/bash if [ ! -f "userlist.txt" ]; then echo "userlist.txt 不存在!" fi for userid in `(cat userlist.txt)` do a=$userid echo $a done #!bin/bash if [ ! -f userlist.txt ]; then echo "userlist.tx…