Splitting gzipped logfiles without storing the ungzipped splits on disk
You can use the split --filter
option as explained in the manual e.g.
zcat biglogfile.gz | split -l500000 --filter='gzip > $FILE.gz'
Edit: not aware when --filter
option was introduced but according to comments, it is not working in core utils 8.4
.
download part of gzipped text file
No, it is not possible. You need to decompress all of the data in a gzip file in order to get the uncompressed data at the end.
Split a large, compressed file into multiple outputs using AWK and BASH
This little perl script does the job nicely
- keeping all destination files open for performance
- doing error elementary handling
- Edit now also pipes output through
gzip
on the fly
There is a bit of a kludge with $fh
because apparently using the hash entry directly doesn't work
#!/usr/bin/perl
use strict;
use warnings;
my $suffix = ".txt.gz";
my %pipes;
while (my ($id, $line) = split /\t/,(<>),2)
{
exists $pipes{$id}
or open ($pipes{$id}, "|gzip -9 > '$id$suffix'")
or die "can't open/create $id$suffix, or cannot spawn gzip";
my $fh = $pipes{$id};
print $fh $line;
}
print STDERR "Created: " . join(', ', map { "$_$suffix" } keys %pipes) . "\n"
Oh, use it like
zcat input.gz | ./myscript.pl
Related Topics
How to Cut an Existing Variable and Assign to a New Variable in Bash
Execute Command Line and Return Command Output
Jboss as 7.1.1 Ejb 3:Ejb Pool Error
Ffmpeg Fix Watermark Size or Percentage
Unzip All Files in a Directory
Delete Files with String Found in File - Linux Cli
How Does Ngrok Work Behind a Firewall
Exclude All Permission Denied Messages from "Du"
How to See Linux' View of the Ram in Order to Determinate the Fragmentation
How to Find the Processor/Chip Architecture on Linux
Get Filesystem Mount Point in Kernel Module
How to Fix "Go Not Root Owned"
Suppress Notice of Forked Command Being Killed
Shell Script for Multithreading a Process
How to Append Contents of Multiple Files into One File
How to Do Division with Variables in a Linux Shell
What's the Difference Between "Env" and "Set" (On MAC Os X or Linux)