1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regular expressions in commands

Discussion in 'T&T - Aliases' started by JohnQSmith, Mar 14, 2012.

  1. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Copied from another thread.

    OK. After quite a bit of tweaking and massaging, I finally got a generic regex command created using Vincent Fatica's 4utils plugin. I've only tried it using COPY and REN since that's where I needed it, but I'm sure it'll work on other commands. Just remember, it doesn't do paths.

    Usage:
    Code:
    xcmd <command> <input> <output>
    
    For instance... if I have a bunch of files named in the style of "Firstname X Lastname.doc" and want to rename them in the style of "Lastname, Firstname X.doc", then the command would be
    Code:
    xcmd ren "(.*? .) (.*?)\.doc" "\2, \1.doc"
    
    Caveat emptor, but it works for me. So, here's the alias.
    Code:
    xcmd=for /w %i in (%@quote[::%@unquote[%2]]) %1 %@quote[%@filename[%i]] %@quote[%@xreplace[%@quote[%@unquote[%2]],%@quote[%@unquote[%3]],%@quote[%@filename[%i]]]]
    
    Remember, you can't just copy, paste, and run the alias at the TCC prompt unless you double all the % signs first.
     
    noahcoad likes this.

Share This Page