How to replace underscores with other characters in a filename? - Questions

This is a discussion on How to replace underscores with other characters in a filename? - Questions ; Hi NG! I've got some files named "Title _Author_ _blah_.rar" and I'd like to rename them at once in "Title (Author) (blah).rar" ot something like that. Notice that the underscores are not replaced by a single character but that it ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How to replace underscores with other characters in a filename?

  1. How to replace underscores with other characters in a filename?

    Hi NG!
    I've got some files named "Title _Author_ _blah_.rar" and I'd like to
    rename them at once in "Title (Author) (blah).rar" ot something like
    that. Notice that the underscores are not replaced by a single
    character but that it depends on the leading or trailing space
    character.
    How can I do this quickly, without creating some perl script or
    something similar for the purpose? I've been thinking of a bash
    script, but I'm rather reserved as of using bash because it instantly
    gives me an awful headache when trying to grasp it's awful syntax.
    Well I know I shouldn't but maybe you could achieve convincing me to
    think of bash as of a delicious ice cream (mmmmmhh.... bash...) by
    showing me how impressingly simple it is to do the renamings?
    My apologies if I sound a bit confusing, but anyway: any help would be
    greatly appreciated.

    Thanks!
    Bernd Haller

  2. Re: How to replace underscores with other characters in a filename?

    "0" wrote in message
    news:d106f634.0312210839.700c4378@posting.google.c om

    > I've got some files named "Title _Author_ _blah_.rar" and I'd like to
    > rename them at once in "Title (Author) (blah).rar" ot something like
    > that. Notice that the underscores are not replaced by a single
    > character but that it depends on the leading or trailing space
    > character.
    > How can I do this quickly, without creating some perl script or
    > something similar for the purpose? I've been thinking of a bash
    > script, but I'm rather reserved as of using bash because it instantly
    > gives me an awful headache when trying to grasp it's awful syntax.
    > Well I know I shouldn't but maybe you could achieve convincing me to
    > think of bash as of a delicious ice cream (mmmmmhh.... bash...) by
    > showing me how impressingly simple it is to do the renamings?
    > My apologies if I sound a bit confusing, but anyway: any help would be
    > greatly appreciated.


    I think you're making a mistake by introducing parentheses and spaces into
    filenames that will later bite you in unexpected ways, but I also think that
    everyone should be free to go to hell in their own chosen way. Also, the
    less willing you are to learn about bash, sed and other fundamental *nix
    utilities, the more you're going to have to be dependent on others to do
    your thinking for you.

    To illustrate using your example(s) above:

    $ touch "Title _Author_ _blah0_.rar" \
    "Title _Author_ _blah1_.rar" \
    "Title _Author_ _blah2_.rar"

    $ ls *.rar
    Title _Author0_ _blah0_.rar
    Title _Author1_ _blah1_.rar
    Title _Author2_ _blah2_.rar

    $ for i in *.rar
    do
    mv "$i" "`echo $i | sed -e 's/ _/ (/1' -e 's/_ /) /1' -e 's/ _/ (/1' -e
    's/_\./)./'`"
    done

    $ ls *.rar
    Title (Author0) (blah0).rar
    Title (Author1) (blah1).rar
    Title (Author2) (blah2).rar



    tony

    --
    use hotmail for any email replies



    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

  3. Re: How to replace underscores with other characters in a filename?

    I wrote in message news:3fe5dfae_6@corp.newsgroups.com

    Hopefully the line wrap is gone:

    > To illustrate using your example(s) above:
    >
    > $ touch "Title _Author0_ _blah0_.rar" \
    > "Title _Author1_ _blah1_.rar" \
    > "Title _Author2_ _blah2_.rar"
    >
    > $ ls *.rar
    > Title _Author0_ _blah0_.rar
    > Title _Author1_ _blah1_.rar
    > Title _Author2_ _blah2_.rar
    >
    > $ for i in *.rar
    > do
    > mv "$i" "`echo $i | sed -e 's/ _/ (/1' -e 's/_ /) /1' -e 's/ _/ (/1' -e 's/_\./)./'`"
    > done
    >
    > $ ls *.rar
    > Title (Author0) (blah0).rar
    > Title (Author1) (blah1).rar
    > Title (Author2) (blah2).rar


    --
    use hotmail for any email replies


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

  4. Re: How to replace underscores with other characters in a filename?

    Wow... I must thank you a lot. I'm going to search for some sed
    tutorial now, it's just that the man page was so ugly that I had never
    tried to decrypt it. This time it's for good. I'll hopefully never
    post such simple questions anymore. Let's hope so
    Thanks again!
    Bernd Haller

    "ynotssor" <"ynotssor"> wrote in message news:<3fe5e158_6@corp.newsgroups.com>...
    > I wrote in message news:3fe5dfae_6@corp.newsgroups.com
    >
    > Hopefully the line wrap is gone:
    >
    > > To illustrate using your example(s) above:
    > >
    > > $ touch "Title _Author0_ _blah0_.rar" \
    > > "Title _Author1_ _blah1_.rar" \
    > > "Title _Author2_ _blah2_.rar"
    > >
    > > $ ls *.rar
    > > Title _Author0_ _blah0_.rar
    > > Title _Author1_ _blah1_.rar
    > > Title _Author2_ _blah2_.rar
    > >
    > > $ for i in *.rar
    > > do
    > > mv "$i" "`echo $i | sed -e 's/ _/ (/1' -e 's/_ /) /1' -e 's/ _/ (/1' -e 's/_\./)./'`"
    > > done
    > >
    > > $ ls *.rar
    > > Title (Author0) (blah0).rar
    > > Title (Author1) (blah1).rar
    > > Title (Author2) (blah2).rar


  5. Re: How to replace underscores with other characters in a filename?

    "0" wrote in message
    news:d106f634.0312220330.3ad51942@posting.google.c om

    > Wow... I must thank you a lot. I'm going to search for some sed
    > tutorial now, it's just that the man page was so ugly that I had never
    > tried to decrypt it. This time it's for good. I'll hopefully never
    > post such simple questions anymore. Let's hope so


    Well, the answer is probably a bit more cryptic than you'd like, but each of
    the -e 's/x/y/?' expressions is where the magic is at. You can learn a very
    small yet very useful thing by studying each of those -e expressions and
    understanding how they relate to your example filename mods.

    tony

    --
    use hotmail for any email replies



    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

+ Reply to Thread