Commands tagged xmlstarlet (8)

  • 9
    xmlstarlet sel -t -c "/path/to/element" file.xml
    kev · 2011-12-19 06:20:46 1
  • Prints the value of a XML node rather than the entire node.

    xmlstarlet sel -t -v "/path/to/element" file.xml
    djangofan · 2011-12-21 21:49:56 0
  • This lengthy cryptic line will print the latest top 10 posts without their summaries. To print also their respective summaries use the following (even bigger) command line: wget -qO - | xmlstarlet sel -T -t -o '<doc>' -n -t -m rss/channel/item -o '<item>' -n -o '<title>' -v title -o '</title>' -n -o '<description>' -v description -o '</description>' -n -o '</item>' -n -t -o '</doc>' | xmlstarlet sel -T -t -m doc/item -v description/code -n -v title -n -n It is recommended to include this line into a shell script to be easily run, as I do myself. You could also use the following URLs to browse the top 3 commands: wget -qO - | xmlstarlet ... .. or all others: wget -qO - | xmlstarlet ... PS: You need to install "xmlstarlet" to run it. It is found in Debian APT repositories (apt-get install xmlstarlet) or under the URL. Show Sample Output

    wget -qO - | xmlstarlet sel -T -t -o '&lt;x&gt;' -n -t -m rss/channel/item -o '&lt;y&gt;' -n -v description -o '&lt;/y&gt;' -n -t -o '&lt;/x&gt;' | xmlstarlet sel -T -t -m x/y -v code -n
    fsilveira · 2009-08-14 02:44:00 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
  • 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
  • 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

  • 0
    xml fo -e utf-8 file.xml | xml esc
    kev · 2011-11-08 07:51:40 0

  • 0
    curl -su username:passwd | xmlstarlet sel -N x="" -t -m //x:entry -v 'concat(position(), ":", x:title)' -n
    kev · 2012-05-05 14:34:55 0

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

Set laptop display brightness
Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video). $ cat /proc/acpi/video/VGA/LCD/brightness to discover the possible values for your display.

Efficiently extract lines between markers
GNU Sed can 'address' between two regex, but it continues parsing through to the end of the file. This slight alteration causes it to terminate reading the input file once the STOP match is made. In my example I have included an extra '/START/d' as my 'start' marker line contains the 'stop' string (I'm extracting data between 'resets' and using the time stamp as the 'start'). My previous coding using grep is slightly faster near the end of the file, but overall (extracting all the reset cycles in turn) the new SED method is quicker and a lot neater.

Search previous commands from your .bash_history
This is not actually a command, it's just a keyboard shortchut. But a very useful one.

Print all the lines between 10 and 20 of a file
Similarly, if you want to print from 10 to the end of line you can use: sed -n '10,$p' filename This is especially useful if you are dealing with a large file. Sometimes you just want to extract a sample without opening the entire file. Credit goes to wbx & robert at the comments section of

Remote backups with tar over ssh
Execute it from the source host, where the source files you wish backup resides. With the minus '-' the tar command deliver the compressed output to the standar output and, trough over the ssh session to the remote host. On the other hand the backup host will be receive the stream and read it from the standar input sending it to the /path/to/backup/backupfile.tar.bz2

Create a bunch of dummy text files
Using the 'time' command, running this with 'tr' took 28 seconds (and change) each time but using base64 only took 8 seconds (and change). If the file doesn't have to be viewable, pulling straight from urandom with head only took 6 seconds (and change)

List Listen Port by numbers
Show TCP Listen ports sorted by number (bugs: IPV6 addresses not supported)

Print a row of characters across the terminal
shorter than alternative

Print text string vertically, one character per line.

search ubuntu packages to find which package contains the executable program programname
search ubuntu's remote package source repositories for a specific program to see which package contains it

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: