Find the answer to your Linux question:
Results 1 to 9 of 9
Hi, I have a script 1)Taking the titles from .cue files with grep. When a title contains a special character such as "é , å , ă, ü" or others ...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    47

    grep/echo with accented/special characters like é , å , ă, ß, ü

    Hi,
    I have a script
    1)Taking the titles from .cue files with grep. When a title contains a special character such as "é , å , ă, ü" or others like ß, grep cannot encode it correctly and I see this symbol: �
    G�recki - String Quartet No. 1
    and not
    Górecki - String Quartet No. 1
    2)Renaming each mp3 file I have with the title using echo. As a result I get bad titles.
    How do I solve this?
    Thanks!
    alex

  2. #2
    Just Joined!
    Join Date
    Jul 2009
    Posts
    58
    There are a million ways of doing this, in perl its rather easy. If you have to use shell script, you can use awk/sed/tr, you can even use iconv if the character set is always the same.

    Something as simple as:

    # echo fóó | tr 'ó' 'o'
    foo

    would work

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    47
    Thanks for you answer, but is there a way to keep those characters ? with awk/tr etc I substitute them. Now I study how iconv works.

  4. #4
    Just Joined!
    Join Date
    Jul 2009
    Posts
    58
    Oh I see, sorry I misunderstood your question.

    That is strange because grep shouldn't care about the unicode nature of the character.

    Can you try using 'grep -b' or 'grep -U'? Does that work?

    If not, provide a sample file and sample command that should work. We'll see what it looks like

  5. #5
    Just Joined!
    Join Date
    Nov 2008
    Posts
    47
    No, -b messes it up even more and -U does nothing. My script opens the .cue file, greps TITLE and stores in in a file,then reads it and changes the names of the .mp3 files. Now I think the problem is not in the grep, but in a sub-script that I use to read a file: make a test.cue file with inside one title like:
    TITLE "Ouverture sur des thèmes Hébreux Op 34b"
    and read it with this function read_file.lib :
    counter=0
    while IFS='\012' read -r LINE
    do
    title[counter]="$LINE";
    let counter=$counter+1 #counter
    done < $1
    export title
    echo "${title[1]}"
    I get:
    read_file.lib test.cue
    TITLE "Ouverture sur des th�mes H�breux Op 34b"

    thanks

  6. #6
    Just Joined!
    Join Date
    Jul 2009
    Posts
    58
    I didn't actually try your script, but from what I can tell this seems like a lot of work to rewrite `head`.

    title =`head -1 $1`

    And head will keep your characters intact.

  7. #7
    Just Joined!
    Join Date
    Nov 2008
    Posts
    47
    Right, but if my .cue file has more lines I cannot put them in separate variables with head. In my previous script I put each line of the file to be read in the array "titles". And actually head has the same problem:
    $ head -1 test.cue
    TITLE "Ouverture sur des th�mes H�breux Op 34b"

  8. #8
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I'm curious: do you see the special characters normally in your terminal ever? I wonder if maybe your terminal doesn't support Unicode. Because head and grep should definitely support Unicode.
    DISTRO=Arch
    Registered Linux User #388732

  9. #9
    Just Joined!
    Join Date
    Nov 2008
    Posts
    47
    indeed I cannot see it with less or head:
    TITLE "Ouverture sur des th<E8>mes H<E9>breux Op 34b"
    but today,while I was tinkering with the script I managed somehow to visualize the characters in the terminal.

Posting Permissions

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