Categories

Tuesday 11 March 2014

How to Delete a line from gz file having huge size

Hi,

We got a task to delete a specific line from a 6Gb gzip file. Below is the steps followed to delete the line.

1)Use zgrep to search through the gzip files

zgrep is used to search a line or pattern from the gzipped file. The output will be same as that of grep command on a normal file. Here we use the command as below. There is a specific pattern on that line through which we need to find the line number and then delete the line from that file using sed.

zgrep -in pattern test1.gz

2)From the above command we got the line number which we need to delete. It is 5344402. Then we need to use sed command to delete line on that line number. But we can't use sed on a gzipped file. So we need to unzip the file

unzip test.gzsya

3)Now we can use sed command to delete that line from the test file

sed -i '5344402d' test

Above command will delete the line on that line number of the file.

4)Again zip the file

zip test






Thats all
Thanks

No comments:

Post a Comment

Ad