The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ftp :bin and ascii smehra UNIX for Advanced & Expert Users 1 03-08-2005 06:22 PM
ascii to dbf HELP! gseyforth UNIX for Advanced & Expert Users 1 12-10-2004 11:58 AM
ascii melkor UNIX for Dummies Questions & Answers 3 12-12-2003 06:33 PM
Ascii To Hex augustinep UNIX for Dummies Questions & Answers 1 04-26-2002 11:03 AM
ascii for EOF ??? strpeski UNIX for Dummies Questions & Answers 3 03-16-2002 05:33 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Jun 2008
Posts: 9
URL to ASCII

I am writing a small script to help me clean out my music (itunes) that has somehow doubled every song. Using the itunes.xml file, I have been able to create a simple list of all the files. The problem is itunes uses URL style formatting, ex. %20 for spaces. I used sed to convert %20 to a space only to find out every special character(!, ?, etc.) is like this. Is there a quick way to convert all URL (hexadecimal I believe) to regular ASCII? Thanks for the help.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
Works in bash and ksh:

Code:
$ url="Does%20it%20work%3F"
$ printf ${url//%/\\x}
Reply With Quote
  #3 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Jun 2008
Posts: 9
Thanks, that worked great. I hope you can help me out with one more thing. I have a text file that I am trying to filter. Here is part of my script:
Code:
while read URL
do
  echo $URL | printf ${URL//%/\\x} > $itunes_file
done < $itunes_file
Before running though the script, the file looks like this:
/Volumes/Diego_External/Music/Jewel/VH-1 Storytellers/06 Who Will Save Your Soul 1.mp3
/Volumes/Diego_External/Music/Jewel/Women & Songs %5BRhino%5D/03 Intuition 1.mp3
After I run it, I get:
/Volumes/Diego_External/Music/Jewel/VH-1

Thanks again.
Reply With Quote
  #4 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
You can protect the spaces with the double quote:
Code:
printf "${URL//%/\\x}"
Reply With Quote
  #5 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Jun 2008
Posts: 9
That fixed it, along with changing to >> not >. Unfortunately, that wasn't the only problem. It still has %5B, %5D, etc that aren't converted with the script. I think at this point, it might be easier to simply search and replace with a text editor. Thanks Ripat.
Reply With Quote
  #6 (permalink)  
Old 06-11-2008
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
Well, that's strange. In your shell do this:
Code:
$ printf "\x5B"
$ printf "\x5D"
In my bash and ksh it correctly returns [ and ]
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0