zoukankan      html  css  js  c++  java
  • (转)shell:读取文件的每一行内容并输出

    写法一:
    ----------------------------------------------------------------------------
    #!/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

    $ cat file | while read line; do echo $line; done
    aaaa
    bbbb
    cccc dddd

    $ for line in $(<file); do echo $line; done
    aaaa
    bbbb
    cccc
    dddd

     
    == 实践 === 
    #! bin/sh
     
    #$str='http://images.stylight.de/static/res200/s2870/2870657.1.jpg%0D'
    #echo ${str##*fo}
    #echo ${str#fo}
    while read line
    do
       wget -p ${line:0:59}
    done < '/root/mysql/mysql.log';
     
    原文链接:http://www.cnblogs.com/iloveyoucc/archive/2012/07/10/2585529.html
  • 相关阅读:
    .NET Core MVC下的TagHelper
    测试.NET core MiddleWare 运行逻辑
    中台
    VSCode 完美整合前后端框架(angular2+.NET core)
    三分钟热度并非贬义
    【算法】莫队算法粗略讲解
    【题解】洋溢着希望
    【三角学】三角恒等变换公式推导
    【题解】方差
    【数据结构】FHQ Treap 详解
  • 原文地址:https://www.cnblogs.com/sfnz/p/5980904.html
Copyright © 2011-2022 走看看