Commands tagged xml (28)

  • Diffs two xml files by formatting them first using xmllint and then invoking diff. Usage: diffxml XMLFile1 XMLFile2


    13
    diffxml() { diff -wb <(xmllint --format "$1") <(xmllint --format "$2"); }
    sharfah · 2011-10-06 07:36:13 5
  • 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


    8
    tidy -i -xml <inputfile>
    Testuser_01 · 2012-11-03 18:10:58 5
  • Limited, but useful construct to extract text embedded in XML tags. This will only work if bar is all on one line. If nobody posts an alternative for the multiline sed version, I'll figure it out later...


    4
    sed -n 's/.*<foo>\([^<]*\)<\/foo>.*/\1/p'
    recursiverse · 2009-07-23 07:59:30 3
  • poor man's xml parser :)


    4
    xml2 < file.xml | grep ^/path/to/element | cut -f2- -d=
    bandie91 · 2011-12-19 18:51:17 4
  • If everything validates, there's no output. Can be handy to run on a cron job set up to email output.


    2
    find -type f -name "*.xml" -exec xmllint --noout {} \;
    bradbeattie · 2011-01-25 18:26:57 5

  • 2
    echo '<foo><bar/></foo>' | xmllint --format -
    akavel · 2012-01-12 09:39:56 23
  • The difference between the original version provided and this one is that this one works rather than outputting a wget error


    2
    curl $1 | grep -E "http.*\.mp3" | sed "s/.*\(http.*\.mp3\).*/\1/" | xargs wget
    theodric · 2015-09-17 13:19:53 30
  • Like `tidy`, `xmllint` can be used to prettify XML files. The --nsclean option is also useful to remove redundant namespaces.


    1
    xmllint --format --xmlout --nsclean <file>
    seb1245 · 2012-11-27 06:13:23 4
  • Neither of the others worked for me. This does.


    1
    curl http://url/rss | grep -o '<enclosure url="[^"]*' | grep -o '[^"]*$' | xargs wget -c
    dakira · 2016-05-29 12:07:21 21
  • Formats the output from `ioreg` into XML, then parses the XML with `xmllint`'s xpath feature. Show Sample Output


    1
    ioreg -ad2 -c IOPlatformExpertDevice | xmllint --xpath '//key[.="IOPlatformUUID"]/following-sibling::*[1]/text()' -
    n8felton · 2018-08-18 21:19:47 349
  • Directly download all mp3 files of the desired podcast


    1
    curl http://radiofrance-podcast.net/podcast09/rss_14726.xml | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*mp3" | sort -u | xargs wget
    pascalvaucheret · 2021-08-09 13:40:26 178
  • 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


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


    0
    curl -u <username> http://app.boxee.tv/api/get_queue | xml2 | grep /boxeefeed/message/description | awk -F= '{print $2}'
    Strawp · 2010-01-20 16:17:19 547
  • 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


    0
    curl -L -s `curl -s http://www.2600.com/oth-broadband.xml` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
    denzuko · 2010-07-30 23:20:50 3
  • Gets the latest podcast show from from your favorite Podcast. Uses curl and xmlstarlet. Make sure you change out the items between brackets.


    0
    curl -L -s `curl -s [http://podcast.com/show.rss]` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
    denzuko · 2010-07-31 00:17:47 3
  • this simply curls the feed and runs a xpath query on it ... Show Sample Output


    0
    atomtitles () { curl --silent $1 | xmlstarlet sel -N atom="http://www.w3.org/2005/Atom" -t -m /atom:feed/atom:entry -v atom:title -n}
    Seebi · 2010-12-15 11:03:31 6
  • This function uses xmllint to evaluate xpaths. Usage: xpath /some/xpath XMLfile Show Sample Output


    0
    xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
    sharfah · 2011-10-05 07:45:16 14
  • The XML document can be transformed to text, XML, HTML or anything else. The --stringparam option allows to set XSL variables externally.


    0
    xsltproc --stringparam name value <xsl_stylesheet> <xml_document>
    seb1245 · 2012-11-09 15:54:46 6
  • OpenDocument documents from OpenOffice.org,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 !


    0
    unzip document.odt content.xml && xmlindent -w content.xml && nano content.xml
    arthurdent · 2012-12-01 17:05:28 6
  • set BLOCK to "title" or any other HTML / RSS / XML tag and curl URL to get everything in-between e.g. some text


    0
    curl ${URL} 2>/dev/null|grep "<${BLOCK}>"|sed -e "s/.*\<${BLOCK}\>\(.*\)\<\/${BLOCK}\>.*/\1/g"
    c3w · 2013-08-31 14:53:54 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


    0
    wget -q -O- http://example-podcast-feed.com/rss | grep -o "<enclosure[ -~][^>]*" | grep -o "http://[ -~][^\"]*" | xargs wget -c
    talha131 · 2013-09-24 12:38:08 22
  • 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


    0
    xmlpager() { xmlindent "$@" | awk '{gsub(">",">'`tput setf 4`'"); gsub("<","'`tput sgr0`'<"); print;} END {print "'`tput sgr0`'"}' | less -r; }
    hackerb9 · 2015-07-12 09:22:10 11
  • 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


    0
    wget -q -O- http://www.yourfeed.com/rss | grep -o "<link[ -~][^>]*" | grep -o "http://www.myfeed.com[ -~][^\"]*" | sed "s: :%20:g" | xargs wget -c
    dermidgen · 2015-10-30 22:13:43 24

  • 0
    wget `curl -s <podcast feed URL> | grep -o 'https*://[^"]*mp3' | head -1`
    tbon3r · 2017-07-16 23:02:03 25
  • For debian likes, that's in python-xml package.


    -1
    xmlproc_parse.python-xml &>/dev/null <FILE> || exit 1
    sputnick · 2009-12-11 17:30:03 5
  •  1 2 > 

What's this?

commandlinefu.com 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

Reads a CD/DVD and creates an dvdisaster iso image with the advanced RS02 method.

Recursivly search current directory for files larger than 100MB

Skip filenames with control characters, a.k.a tab,newline etc

Recursive grep of all c++ source under the current directory
I like this better than some of the alternatives using -exec, because if I want to change the string, it's right there at the end of the command line. That means less editing effort and more time to drink coffee.

Display packages and versions on Debian/Ubuntu distrib
Need admin right to run dpkg-query

Chronometer in hour format
Shorter and faster...

display a smiling smiley if the command succeeded and a sad smiley if the command failed
you could save the code between if and fi to a shell script named smiley.sh with the first argument as and then do a smiley.sh to see if the command succeeded. a bit needless but who cares ;)

find largest file in /var
find largest file in /var

Extracts PDF pages as images

Make a DVD ISO Image from a VIDEO_TS folder on MacOSX
/path/ is the root folder of the DVD, not the VIDEO_TS folder.


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: