How to do a mass rename?

前端 未结 11 2026
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 06:23

I need to rename files names like this

transform.php?dappName=Test&transformer=YAML&v_id=XXXXX

to just this

XXXXX.t         


        
11条回答
  •  感情败类
    2020-11-27 06:54

    You write a fairly simple shell script in which the trickiest part is munging the name.

    The outline of the script is easy (bash syntax here):

    for i in 'transform.php?dappName=Test&transformer=YAML&v_id='*
    do
        mv $i 
    done
    

    Modifying the name has many options. I think the easiest is probably an awk one-liner like

    `echo $i  |  awk -F'=' '{print $4}'`
    

    so...

    for i in 'transform.php?dappName=Test&transformer=YAML&v_id='*
    do
        mv $i `echo $i |  awk -F'=' '{print $4}'`.txt 
    done
    

    update

    Okay, as pointed out below, this won't necessarily work for a large enough list of files; the * will overrun the command line length limit. So, then you use:

    $ find . -name 'transform.php?dappName=Test&transformer=YAML&v_id=*' -prune -print |
    while read
    do
        mv $reply `echo $reply |  awk -F'=' '{print $4}'`.txt 
    done
    

提交回复
热议问题