Commands tagged xml (26)

  • 0
    wget `curl -s <podcast feed URL> | grep -o 'https*://[^"]*mp3' | head -1`
    tbon3r · 2017-07-16 23:02:03 0
  • Neither of the others worked for me. This does.

    curl http://url/rss | grep -o '<enclosure url="[^"]*' | grep -o '[^"]*$' | xargs wget -c
    dakira · 2016-05-29 12:07:21 0
  • Just added a little url encoding with sed - urls with spaces don't work well - this also works against instead of enclosure and adds a sample to show that you can filter against links at a certain domain Show Sample Output

    wget -q -O- | grep -o "<link[ -~][^>]*" | grep -o "[ -~][^\"]*" | sed "s: :%20:g" | xargs wget -c
    dermidgen · 2015-10-30 22:13:43 0
  • The difference between the original version provided and this one is that this one works rather than outputting a wget error

    curl $1 | grep -E "http.*\.mp3" | sed "s/.*\(http.*\.mp3\).*/\1/" | xargs wget
    theodric · 2015-09-17 13:19:53 1
  • Don't want to open up an editor just to view a bunch of XML files in an easy to read format? Now you can do it from the comfort of your own command line! :-) This creates a new function, xmlpager, which shows an XML file in its entirety, but with the actual content (non-tag text) highlighted. It does this by setting the foreground to color #4 (red) after every tag and resets it before the next tag. (Hint: try `tput bold` as an alternative). I use 'xmlindent' to neatly reflow and indent the text, but, of course, that's optional. If you don't have xmlindent, just replace it with 'cat'. Additionally, this example shows piping into the optional 'less' pager; note the -r option which allows raw escape codes to be passed to the terminal. Show Sample Output

    xmlpager() { xmlindent "$@" | awk '{gsub(">",">'`tput setf 4`'"); gsub("<","'`tput sgr0`'<"); print;} END {print "'`tput sgr0`'"}' | less -r; }
    hackerb9 · 2015-07-12 09:22:10 0
  • This script can be used to download enclosed files from a RSS feed. For example, it can be used to download mp3 files from a podcasts RSS feed. Show Sample Output

    wget -q -O- | grep -o "<enclosure[ -~][^>]*" | grep -o "http://[ -~][^\"]*" | xargs wget -c
    talha131 · 2013-09-24 12:38:08 0
  • set BLOCK to "title" or any other HTML / RSS / XML tag and curl URL to get everything in-between e.g. some text

    curl ${URL} 2>/dev/null|grep "<${BLOCK}>"|sed -e "s/.*\<${BLOCK}\>\(.*\)\<\/${BLOCK}\>.*/\1/g"
    c3w · 2013-08-31 14:53:54 0
  • OpenDocument documents from,LibreOffice and other applications, are actually ZIP archives. Useful informations in these archives are in XML format. Here we like it or do not. Anyway, the XML files have the unfortunate tendency to not be indented, and for good reason: they consist of only one line! To solve the problem and to use a proper editor on the content, I proceed as follows. Required xmlindent You can also use : zip document.odt content.xml And it works with vi instead of nano !

    unzip document.odt content.xml && xmlindent -w content.xml && nano content.xml
    arthurdent · 2012-12-01 17:05:28 0
  • Like `tidy`, `xmllint` can be used to prettify XML files. The --nsclean option is also useful to remove redundant namespaces.

    xmllint --format --xmlout --nsclean <file>
    seb1245 · 2012-11-27 06:13:23 0
  • The XML document can be transformed to text, XML, HTML or anything else. The --stringparam option allows to set XSL variables externally.

    xsltproc --stringparam name value <xsl_stylesheet> <xml_document>
    seb1245 · 2012-11-09 15:54:46 0
  • This will indent the input to be more readable. Warnings and messages are not send to STDOUT so you can just use a pipe to create the formatted outputfile, like: tidy -i -xml in.xml > out.xml Show Sample Output

    tidy -i -xml <inputfile>
    Testuser_01 · 2012-11-03 18:10:58 0

  • 2
    echo '<foo><bar/></foo>' | xmllint --format -
    akavel · 2012-01-12 09:39:56 0
  • This function uses xmllint to evaluate xpaths. Usage: xpath /path/to/element XMLfile

    xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
    sharfah · 2011-12-20 08:34:11 0
  • poor man's xml parser :)

    xml2 < file.xml | grep ^/path/to/element | cut -f2- -d=
    bandie91 · 2011-12-19 18:51:17 1
  • Diffs two xml files by formatting them first using xmllint and then invoking diff. Usage: diffxml XMLFile1 XMLFile2

    diffxml() { diff -wb <(xmllint --format "$1") <(xmllint --format "$2"); }
    sharfah · 2011-10-06 07:36:13 1
  • This function uses xmllint to evaluate xpaths. Usage: xpath /some/xpath XMLfile Show Sample Output

    xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
    sharfah · 2011-10-05 07:45:16 0
  • Removes all lines between the lines containing "" and "", including these lines itself Backdrop: Sometimes when working with XML files without an graphical editor, large comment-/annotation-blocks taper the readability to walk through the file. I like to create a copy of such documents without these annotations. As the documentation itself is in documentation tags inside the annotation tags an therefore graphical editors tend to put the annotation tags in their own lines, this command removes all documentations within annotation-tags. Show Sample Output

    awk "/<xsd:annotation>/{h=1};!h;/<\/xsd:annotation>/{h=0}" annotatedSchema.xsd
    2chg · 2011-07-15 07:17:17 1
  • If everything validates, there's no output. Can be handy to run on a cron job set up to email output.

    find -type f -name "*.xml" -exec xmllint --noout {} \;
    bradbeattie · 2011-01-25 18:26:57 0
  • this simply curls the feed and runs a xpath query on it ... Show Sample Output

    atomtitles () { curl --silent $1 | xmlstarlet sel -N atom="" -t -m /atom:feed/atom:entry -v atom:title -n}
    Seebi · 2010-12-15 11:03:31 0
  • I use this command in my Conky script to display the number of messages in my Gmail inbox and to list the from: and subject: fields. Show Sample Output

    wget -O - '' --no-check-certificate
    PLA · 2010-09-26 14:47:13 3
  • Gets the latest podcast show from from your favorite Podcast. Uses curl and xmlstarlet. Make sure you change out the items between brackets.

    curl -L -s `curl -s []` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
    denzuko · 2010-07-31 00:17:47 0
  • Ever wanted to stream your favorite podcast across the network, well now you can. This command will parse the iTunes enabled podcast and stream the latest episode across the network through ssh encryption. Show Sample Output

    curl -L -s `curl -s` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
    denzuko · 2010-07-30 23:20:50 0
  • Might be able to do it in less steps with xmlstarlet, although whether that would end up being shorter overall I don't know - xmlstarlet syntax confuses the heck out of me. Prompts for your password, or if you're a bit mental you can add your password into the command itself in the format "-u user:password". Show Sample Output

    curl -u <username> | xml2 | grep /boxeefeed/message/description | awk -F= '{print $2}'
    Strawp · 2010-01-20 16:17:19 4
  • For debian likes, that's in python-xml package.

    xmlproc_parse.python-xml &>/dev/null <FILE> || exit 1
    sputnick · 2009-12-11 17:30:03 1
  • This one will work a little better, the regular expressions it is not 100% accurate for XML parsing but it will suffice any XML valid document for sure. Show Sample Output

    grep -Eho '<[a-ZA-Z_][a-zA-Z0-9_-:]*' * | sort -u | cut -c2-
    inkel · 2009-08-05 21:54:29 0
  •  1 2 > 

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Replace multiple file extensions with a single extension
The above is just a prove of concept based around the nested bash substitution. This could be useful in situations where you're in a directory with many filetypes but you only want to convert a few. $ for f in *.bmp *.jpg *.tga; do convert $f ${f%.*}.png; done or you can use ls | egrep to get more specific... but be warned, files with spaces will cause a ruckus with expansion but the bash for loop uses a space delimited list. $ for f in $(ls | egrep "bmp$|jpg$|tga$"); do convert $f ${f%.*}.png; done I'm guessing some people will still prefer doing it the sed way but I thought the concept of this one was pretty neat. It will help me remember bash substitutions a little better :-P

list block devices
Shows all block devices in a tree with descruptions of what they are.

know the current running shell (the true)
Return the current shell. It is better than print $SHELL which can sometimes return a false value.

find co-ordinates of a location
Just add this to your .bashrc file. Use quotes when query has multiple word length.

Extract all 404 errors from your apache accesslog (prefix lines by occurrences number)

Inverted cowsay
It's quite fun to invert text using "" (ref: ). Slightly more challenging is to flip a whole "cowsay". :-)

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

List bash functions defined in .bash_profile or .bashrc

Get all these commands in a text file with description.
I tried out on my Mac, jot to generate sequence ( 0,25,50,..), you can use 'seq' if it is linux to generate numbers, need curl installed on the machine, then it rocks. @Satya

Capture screen and mic input using FFmpeg and ALSA
Yet another x11grab using ffmpeg. I also added mic input to the capturing video stream using alsa. Yet I need to find out how to capture audio which is currently playing.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: