shell脚本按行循环读取文件内容

while IFS= read -r line
do
  length=${#line}
  if (($length<181)); then
    continue
  fi
  str1=${line:115:2}
  str2=${line:118:2}
  str3=${line:121:2}
  str4=${line:124:2}
  str6="ext data"
  str=$str4$str3$str2$str1
  str7=${line:127:24}
  printf "%s\t%s\t%s\n" "$str" "$str7" "$str6" >> ./test3.txt
  echo $str
done < ./test2.txt

"IFS="  表示将输入的行按原样传递给变量"line",不会去掉行首行尾的空格或制表符

"read"会从读取标准输入一行并存储到"line",使用"< ./test2.txt"重定向则会从文件一行一行读

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值