美文网首页
shell一个文本拷贝多份

shell一个文本拷贝多份

作者: 一路向后 | 来源:发表于2020-11-28 21:20 被阅读0次

    1.编写脚本

    #!/bin/bash
    
    f=$2
    
    a=$(echo $f | grep -o '{[0-9]*-[0-9]*}')
    b=$(echo $a | awk -F '-' '{print $1}' | cut -c 2-)
    b=${b##0}
    c=$(echo $a | awk -F '-' '{print $2}' | awk -F '}' '{print $1}')
    c=${c##0}
    
    d=$(echo $f | grep -o '.*{')
    d=${d%%[\{]}
    e=$(echo $f | grep -o '}.*')
    e=${e##[\}]}
    
    #echo $b $c
    
    g=$(seq $b $c)
    
    for i in $g
    do
            #echo "$d$i$e"
            cp $1 "$d$i$e"
    done
    

    2.运行脚本

    $ ./copy.sh hello.sh hello{1-9}.sh
    

    3.查看结果

    $ ls
    copy.sh  hello1.sh  hello2.sh  hello3.sh  hello4.sh  hello5.sh  hello6.sh  hello7.sh  hello8.sh  hello9.sh  hello.sh
    

    相关文章

      网友评论

          本文标题:shell一个文本拷贝多份

          本文链接:https://www.haomeiwen.com/subject/ruicwktx.html