Read a file from a tar archive with VIM without extracting

tar can output archived file contents to STDOUT with the "-O" option, to be piped to other utilities for further processing without having to extract first. I do this rarely enough to always seem to forget, but when reading stuff with VI (and a few other unix utils) from STDIN, must append a dash.

tar xjfO my.archive.bz2 path/to/file/inside/archive | vim -

For gzip compressed archive use "z" instead of "j" or ommit both if uncompressed.

Other utils, like grep, don't require the dash when piping output to them:

tar xjfO my.archive.bz2 path/to/file/inside/archive | grep --color "search string"

It's all in "man vi", maybe having gone through the trouble of posting this, I'll remember next time.

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).