LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to seek and destroy upside down characters? (in a script if need be) (https://www.linuxquestions.org/questions/programming-9/how-to-seek-and-destroy-upside-down-characters-in-a-script-if-need-be-4175657814/)

BW-userx 07-21-2019 04:04 PM

How to seek and destroy upside down characters? (in a script if need be)
 
how to get rid of upside down characters?

Ramones - ¡Adios Amigos! - 01 - I Don't Want to Grow Up.mp3

I haven't ever started anything yet, because i have no idea how to tell the system to look for upside down characters.

I just want to rip them out of there and rename the files on the go without the upside down characters.

scasey 07-21-2019 04:19 PM

I'd start with the hex or decimal representation and/or figure out how to type them to use in sed or awk.

I'm looking...

BW-userx 07-21-2019 04:33 PM

thanks for the lead, I'll go seek that out...
copy/paste into the command line might work, too.

yep, pretty smart idea...
Code:

[userx@arcomeo ~]$ bob="Ramones - ¡Adios Amigos! - 01 - I Don't Want to Grow Up.mp3"
[userx@arcomeo ~]$ echo -e $bob | sed s'|¡||'
Ramones - Adios Amigos! - 01 - I Don't Want to Grow Up.mp3

################ remove both ############

[userx@arcomeo ¡Adios Amigos!]$ echo -e $bob | sed s'|¡||;s|!||'
Ramones - Adios Amigos - 01 - I Don't Want to Grow Up.mp3

######### DONE ################
[userx@arcomeo ¡Adios Amigos!]$ for i in ./*.mp3 ; do bob=$(echo "$i" | sed s'|¡||;s|!||') ; mv "$i" "$bob" ; done


scasey 07-21-2019 04:52 PM

Haven't figured out how to type them yet...pretty easy in Windows, but need to change the keyboard in Linux, and that's not working for me.

Did find these
Code:

!
ASCII 173
hex A1

?
ASCII 168
hex BF

...tho your copy/paste solution is probably the simplest...

EDIT
A learning: On my Cinnamon desktop, typing Alt+number in an application that uses tabs, switches to that number tab. Very confusing when you're trying things in a multi-tab Firefox window!

BW-userx 07-21-2019 04:55 PM

Quote:

Originally Posted by scasey (Post 6017337)
Haven't figured out how to type them yet...pretty easy in Windows, but need to change the keyboard in Linux, and that's not working for me.

Did find these
Code:

!
ASCII 173
hex A1

?
ASCII 168
hex BF

...tho your copy/paste solution is probably the simplest...

yeah that would be a cool challenge, but I did the copy paste thing. I posted it all in the upper post above.
thanks!!!

individual 07-21-2019 05:05 PM

You can also use tr to remove anything that isn't ASCII.
Code:

echo "Ramones - ¡Adios Amigos! - 01 - I Don't Want to Grow Up.mp3" | tr -cd '\000-\177'
Basic ASCII is in the range of 0 to 127, which is 177 in octal. Unfortunately tr doesn't work with hexadecimal ranges, which would be easier, in my opinion.

ehartman 07-21-2019 11:09 PM

Quote:

Originally Posted by individual (Post 6017343)
Basic ASCII is in the range of 0 to 127, which is 177 in octal. Unfortunately tr doesn't work with hexadecimal ranges, which would be easier, in my opinion.

And watch out for utf-8, ucs-2 and other such multi-byte characters, although at least in utf-8 they're all above 127 (have the highest bit set).
But probably you'll have to change the range to \1-\177, 'cause \0 normally isn't a legal character in text.

grail 07-22-2019 02:24 AM

Probably not what you were looking for, but my 2 cents would be to make the files linux ready, ie remove extraneous characters that are not nix friendly:
Code:

echo "Ramones - ¡Adios Amigos! - 01 - I Don't Want to Grow Up.mp3" | sed -r 's/[^[:alnum:].]+/_/g'


All times are GMT -5. The time now is 06:04 AM.