Skip to content

Instantly share code, notes, and snippets.

@hacolab
Created August 2, 2019 14:38
Show Gist options
  • Save hacolab/1f42708e9367984ebfcdb6a52bdddac7 to your computer and use it in GitHub Desktop.
Save hacolab/1f42708e9367984ebfcdb6a52bdddac7 to your computer and use it in GitHub Desktop.
#!/bin/sh
clean_link_tag() {
# <link rel="name" href="URL" /> ==> <name>URL</name>
sed 's#<link rel="\([^"]*\).*href="\([^"]*\)".*#<\1>\2</\1>#'
}
clean_category_tag() {
# <category term="name" /> ==> <category>name</category>
sed 's#<category term="\([^"]*\)".*$#<category>\1</category>#'
}
clean_auhor_tag() {
sed 's#<name>\(.*\)</name>#\1#'
}
delete_tag_attr() {
# <tagname attr="...">val</tagname> ==> <tagname>val</tagname>
sed 's#^<\([^ >]*\)[^>]*>#<\1>#'
}
sed -e 's/^[ ]*//' -e 's/[ ]*$//' \
| clean_link_tag \
| clean_category_tag \
| clean_auhor_tag \
| delete_tag_attr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment