How to list the first or last 10 lines from a file without decompressing it in linux -
i have .bz2 file. want list first or lastly 10 lines without decompress big. tried head -10 or tail -10 see gibberish. need compare 2 compressed file check if similar or not. how accomplish without decompressing files ?
edit: similar means identical (have same content).
while bzip2 block-based compression algorithm, in theory could find particular blocks want decompress, complicated (e.g. if lastly 10 lines want see spans 2 or more compressed blocks?).
to reply immediate question, can this, decompress entire file, in sense wasteful, doesn't seek store file anywhere, don't run storage capacity issues:
bzcat file.bz2 | head -10 bzcat file.bz2 | tail -10 if distribution doesn't include bzcat (which bit unusual in experience), bzcat equivalent bzip2 -d -c.
however, if ultimate goal compare 2 compressed files (that may have been compressed @ different levels, , comparing actual compressed files straight doesn't work), can (assuming bash shell):
cmp <(bzcat file1.bz2) <(bzcat file2.bz2) this decompress both files , compare uncompressed info byte-by-byte without ever storing either of decompressed files anywhere.
linux
No comments:
Post a Comment