Get line from file at specified byte offset Get line from file at specified byte offset unix unix

Get line from file at specified byte offset


with open(filename, 'r') as f:        for offset in offsets:        f.seek(offset)        print(f.readline())

References:


Quickie perl:

my @offsets = ( 0, 10 );open (my $data, '<', 'file.txt') || die "Can't open input: $!\n";foreach my $offset (@offsets) {    seek( $data, $offset, 0 );    my $line = <$data>;    print $line;}close $data;


seek() to the required byte position, then read. This should be easy from Python and Perl, and doable from shell script (I'm thinking dd).