Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Regular expression help

  • 31-10-2003 10:11AM
    #1
    Registered Users, Registered Users 2 Posts: 2,049 ✭✭✭


    Hi,

    I need help constructing a script that will do the following -

    1. find all filenames that begin with 6 characters (alphanumeric) followed by a '-' AND that end in .jpg.

    2. then I need to rename each of the files so that the first '-' is replaced by a '*' and all remaining '-' are replaced by a space ' '.

    I'm running OSX using the t shell.

    Cheers.

    Michael


Comments

  • Closed Accounts Posts: 85 ✭✭Delboy79


    Is this homework ???


  • Moderators, Arts Moderators Posts: 36,233 Mod ✭✭✭✭pickarooney


    Try this:

    ls [0-Z][0-Z][0-Z][0-Z][0-Z][0-Z]-*.jpg|while read i
    do
    echo $i|sed s/-/*/|sed s'/-/ /'g
    done


  • Closed Accounts Posts: 484 ✭✭ssh


    [0-Z][0-Z][0-Z][0-Z][0-Z][0-Z]-*.jpg

    Should that not be a "-.*.jpg"

    That would only match a file ending in any number of '-'s


Advertisement