I would like to use awk
or similar to match patterns of a chrome bookmarks file and depending on match, cut out a specific field based on different field delimiters.
I have attached a sample picture. I still haven't figured out how to attach as a file.
I want the folder names in case the string H3
is matched and the URL in case the string HREF
is encountered.
the following two commands do the job for the respective matches:
awk -F'[<>]' '/H3/{print $5}' bookmarks.htm
awk -F'"' '/HREF/{print $2}' bookmarks.html
My goal is to combine the two statements above so the output becomes:
UNIX
url-1
url-2
OCE
url-3
url-4
url-5
ANDROID
url-6
url-7
I have tried awk
's if, then, else but wasn't conclusive.
How do I achieve this as a one-liner? are there better candidates than awk
? python, perl would both be great, however, one-liner is an absolute as it would be an easy task writing a shell script that does the job.
{}
button to format the text as code. – Gilles 'SO- stop being evil' Feb 19 '17 at 21:37awk -F'[<>]' '/<H3/{print $5} /HREF="/{sub(/[^"]*"/,"");sub(/".*/,"");print}' bookmark.html
– dave_thompson_085 Feb 21 '17 at 02:53