Webloc files are the handy little URL “aliases” that Mac OSX makes when you drag a URL from your web browser into a file folder. I’ve used them quite a bit to organize links I want to keep for various reasons.
If you’ve ever needed to convert a directory of “webloc” files into text suitable for pasting into an email or document, you want this handy little command:
grep -h http *.webloc | grep -v apple.com | sed -e 's/
To use it, open up the terminal window, cd to the directory which has the webloc files, and type the above command. It will output a list of URLs to the shell that you can easily cut-and-paste into your document.
Update 10-14-09: Just realized that the formatting had gotten messed up in the html encoding, the posted command has been updated now to actually work.
It finally worked for me after one small change:
change the first sed to sed -e ‘s///’
thanks for the acorn!
I don’t know what the first sed originally looked like, but sed -e ‘s///’ does not work for me at all. I get the error “sed: first RE may not be empty” using os x 10.6. I changed it to sed -e ‘s///’. I also replaced the second grep to grep \. With the original grep, the output contained a lot of lines beginning with “Binary file” and the name of the link. Also, the original grep would eliminate any .webloc links to Apple sites. The complete command that I use is:
grep -h http *.webloc | grep \ | sed -e ‘s///’ | sed -e ‘s///’
Whoa! What is happening here? I just posted the above comment, but it has been altered and is not what I submitted. Important text has been filtered out. Try the following:
grep -h http *.webloc | grep BACKSLASH_LESSTHANstringBACKSLASH_GREATERTHAN | sed -e ‘sFORWARDSLASH_LESSTHANstringGREATERTHAN_FORWARDSLASH_FORWARDSLASH’ | sed -e ‘sFORWARDSLASH_LESSTHAN_BACKSLASH_FORWARDSLASHstringGREATERTHAN_FORWARDSLASH_FORWARDSLASH’
The underscores are for legibility and should be interpreted as no space.