Page 4 of 6 FirstFirst ... 23456 LastLast
Results 31 to 40 of 59

Thread: How to search and replace file name characters

  1. #31
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,463
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to search and replace file name characters

    wth? o.O

    inside the loop what happens can be reduced to this:

    Code:
    $ fd='/media/newest3TB/0 test/JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]'
    $ p=${fd%/*}
    $ n=${fd##*/}
    $ echo "p: '$p'"
    p: '/media/newest3TB/0 test'
    $ echo "n: '$n'"
    n: 'JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]'
    $ echo "n2: '${n//[⁄∕:]/-}'"
    n2: 'JON ANDERSON -Lord Of The Rings- The Unreleased Yes Songs -[no label 1CD]'
    $ echo mv -T -- "$fd" "$p/${n//[⁄∕:]/-}"
    mv -T -- /media/newest3TB/0 test/JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD] /media/newest3TB/0 test/JON ANDERSON -Lord Of The Rings- The Unreleased Yes Songs -[no label 1CD]
    this is what i get in terminal when i paste fd='...' and then the code line by line - ':' clearly becomes '-' o.O
    can you repeat that sequence on your machine and paste the output?
    Last edited by Vaphell; March 19th, 2013 at 06:43 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  2. #32
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: How to search and replace file name characters

    strange, doesn't seem to be working here.


    /media/newest3TB/0 test$ fd='/media/newest3TB/0 test/JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]'
    /media/newest3TB/0 test$ p=${fd%/*}
    /media/newest3TB/0 test$ n=${fd##*/}
    /media/newest3TB/0 test$ echo "p: '$p'"
    p: '/media/newest3TB/0 test'
    /media/newest3TB/0 test$ echo "n: '$n'"
    n: 'JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]'
    /media/newest3TB/0 test$ echo "n2: '${n//[⁄∕:]/-}'"
    n2: 'JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]'
    /media/newest3TB/0 test$ echo mv -T -- "$fd" "$p/${n//[⁄∕:]/-}"
    mv -T -- /media/newest3TB/0 test/JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD] /media/newest3TB/0 test/JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]
    Last edited by meanmrmustard; March 19th, 2013 at 07:34 PM.

  3. #33
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,463
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to search and replace file name characters

    o.O
    somehow ${variable//pattern/replacement} doesn't work on your end
    what is your system/bash version?
    Code:
    lsb_release -a
    bash --version
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  4. #34
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: How to search and replace file name characters

    GNU bash, version 4.2.8(1)-release (i686-pc-linux-gnu)
    Copyright (C) 2011 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

    This is Ubuntu 11.04 running xfce desktop

  5. #35
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,149
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to search and replace file name characters

    Maybe it's not a colon after all, but a Unicode Character 'FULLWIDTH COLON'.

  6. #36
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,463
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to search and replace file name characters

    crap, i deleted virtualbox image of 11.04 not long ago, only have 11.10+ and don't feel like installing.

    you say that even simple
    Code:
    $ x='a:b:c'
    $ echo ${x//[⁄∕:]/-}
    a-b-c
    fails?

    tell me, does something like this return the correct result?
    Code:
    $ n='JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]'
    $ echo "$n" | sed -r 's/[⁄∕:]/-/g'
    JON ANDERSON -Lord Of The Rings- The Unreleased Yes Songs -[no label 1CD]
    if so, you can plug it in in place of ${n//.....}
    Code:
    mv -- "$fd" "$p"/"$(echo "$n" | sed -r 's/[⁄∕:]/-/g' )";
    edit:
    as papibe mentioned and i started suspecting this might be an issue with the colon not being the one we think it is, just like there are these other slashes.
    Last edited by Vaphell; March 19th, 2013 at 08:00 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  7. #37
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,149
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to search and replace file name characters

    Quote Originally Posted by papibe View Post
    Maybe it's not a colon after all, but a Unicode Character 'FULLWIDTH COLON'.
    For example:
    Code:
    $ touch "$(python -c 'print "file", u"\uFF1A".encode("utf-8"), "one"')"
    $ touch "file : one"
    $ ls -1 fi*
    file : one
    file : one
    
    $ ls -1 file* | od -a
    0000000   f   i   l   e  sp   :  sp   o   n   e  nl   f   i   l   e  sp
    0000020   o   < sub  sp   o   n   e  nl
    0000030

  8. #38
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: How to search and replace file name characters

    I'm really out of my depth now.
    As if I wasn't already!

  9. #39
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,463
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to search and replace file name characters

    OP, can you copy paste that troublesome colon verbatim into this

    Code:
    $ printf "\\\x%s\n" $(printf ':'|xxd -p -c1 -u)    # standard ascii
    \x3A
    $ printf "\\\x%s\n" $(printf ''|xxd -p -c1 -u)  # fullwidth colon
    \xEF
    \xBC
    \x9A
    sadly in charmap program searching for 'colon' yields many vertically aligned double dots :/



    edit: you might understand now why IT people consider remote helpdesking one of the worst jobs imaginable. Without hands on the problem they are limited to guesswork and asking weird questions that don't make any sense to common folk in hope of pinpointing the source of issues
    Last edited by Vaphell; March 19th, 2013 at 08:19 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  10. #40
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: How to search and replace file name characters

    Quote Originally Posted by Vaphell View Post
    crap, i deleted virtualbox image of 11.04 not long ago, only have 11.10+ and don't feel like installing.

    you say that even simple
    Code:
    $ x='a:b:c'
    $ echo ${x//[⁄∕:]/-}
    a-b-c
    fails?
    /media/newest3TB/0 test$ x='a:b:c'
    /media/newest3TB/0 test$ echo ${x//[⁄∕:]/-}
    a:b:c


    tell me, does something like this return the correct result?
    Code:
    $ n='JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]'
    $ echo "$n" | sed -r 's/[⁄∕:]/-/g'
    JON ANDERSON -Lord Of The Rings- The Unreleased Yes Songs -[no label 1CD]


    /media/newest3TB/0 test$ n='JON ANDERSON -Lord Of The Rings: The Unreleased Yes Songs -[no label 1CD]'
    /media/newest3TB/0 test$ echo "$n" | sed -r 's/[⁄∕:]/-/g'
    JON ANDERSON -Lord Of The Rings- The Unreleased Yes Songs -[no label 1CD]

    Yay!

    if so, you can plug it in in place of ${n//.....}
    Code:
    mv -- "$fd" "$p"/"$(echo "$n" | sed -r 's/[⁄∕:]/-/g' )";
    I'll have to check that when I return in a couple hours.

    BTW, I sure appreciate all your help

    edit:
    as papibe mentioned and i started suspecting this might be an issue with the colon not being the one we think it is, just like there are these other slashes.

Page 4 of 6 FirstFirst ... 23456 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •