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';
  • 相关阅读:
    [CF1263E] Editor
    [CF1288D] Minimax Problem
    [CF1294E] Obtain a Permutation
    [CF770C] Online Courses In BSU
    [CF832D] Misha, Grisha and Underground
    [CF917B] MADMAX
    [CF938D] Buy a Ticket
    [CF959E] Mahmoud and Ehab and the xor-MST
    [CF999E] Reachability from the Capital
    [CF960F] Pathwalks
  • 原文地址:https://www.cnblogs.com/google4y/p/2677887.html
Copyright © 2011-2022 走看看