shell while 读取行

发布时间:2020-06-30 15:32:05 作者:cuizhiliang
来源:网络 阅读:331

for i in cat file 和 while read line的区别

#!/bin/bash
#Auth: andy
#Date: 20191114
#Describe: 统计

word_file="./cui"

###会把每行的单词做为新的每一行的输出
#for i in `cat ./cui`;do
#       l=`echo $i|wc -L`
#       #echo ${l}
#       if [ ${l} -gt 6 ];then
#               echo $i
#       fi
#done

##单词还是在本行里面
a=0
while read line
do
        a=$[a+1]
        echo "第${a} 行内容"
        for i in $line;
        do
                l=`echo $i|wc -L`
                if [ ${l} -gt 6 ];then
                echo -n $i
                fi
        done
        echo 
done < ./cui

while读取是按照shell read 分割符
而 IFS 是一种 set 变量,当 shell 处理"命令替换"和"参数替换"时,shell 根据 IFS 的值,默认是 space, tab, newline 来拆解读入的变量,然后对特殊字符进行处理,最后重新组合赋值给该变量。
shell while 读取行

     直接输出IFS是看不到的,把它转化为二进制就可以看到了,"040"是空格,"011"是Tab,"012"是换行符"\n" 。最后一个 012 是因为 echo 默认是会换行的。

     更改IFS

$ cat 1.txt
1,a
2,b
3,c
4,d
$ cat test.sh
shell while 读取行
采用逗号分割

推荐阅读:
  1. shell脚本按行读取文件内容的方法
  2. 简单的Shell脚本

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

shell while he hell

上一篇:python打开带变量名txt文件的方法

下一篇:如何在Unity中实现物体的二段跳

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》