Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sed on a compressed file

Tags:

linux

shell

sed

I have written a file processing program and now it needs to read from a zipped file(.gz unzipped file may get as large as 2TB),

Is there a sed equivalent for zipped files like (zcat/cat) or else what would be the best approach to do the following efficiently

    ONE=`zcat filename.gz| sed -n $counts`

$counts : counter to read(line by line)

The above method works, but is quite slow for large file as I need to read each line and perform the matching on certain fields.

Thanks

EDIT

Though not directly helpful, here are a set of zcommands

http://www.cyberciti.biz/tips/decompress-and-expand-text-files.html

like image 338
learner Avatar asked Aug 08 '11 18:08

learner


People also ask

How do I use sed to edit a file?

Find and replace text within a file using sed command Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input.txt. The s is the substitute command of sed for find and replace. It tells sed to find all occurrences of 'old-text' and replace with 'new-text' in a file named input.txt.

Does sed modify the original file?

By default sed does not overwrite the original file; it writes to stdout (hence the result can be redirected using the shell operator > as you showed).

What is the ZCAT command used for?

The zcat command allows the user to expand and view a compressed file without uncompressing that file. The zcat command does not rename the expanded file or remove the . Z extension. The zcat command writes the expanded output to standard output.


1 Answers

Well you either can have more speed (i.e. use uncompressed files) or more free space (i.e. use compressed files and the pipe you showed)... sorry. Using compressed files will always have an overhead.

like image 97
C. Ramseyer Avatar answered Oct 15 '22 22:10

C. Ramseyer