Avatar of Andys1
Andys1 asked on

Using gunzip and find command together

Hello,

I want to create separate gunzip files for every year from the all available files in the directory.
File extension starts with YYYYMMDD.tsv. Can anyone please help create te command?

Files would be
20070330.tsv
20070427.tsv
20070531.tsv
20070629.tsv
20070731.tsv
20070831.tsv
20070928.tsv
20071031.tsv
20071130.tsv
20071228.tsv
20080131.tsv
20080229.tsv
20080331.tsv
20080430.tsv
20080530.tsv
20080630.tsv
20080731.tsv
20080829.tsv
20080930.tsv
20081031.tsv
20081128.tsv
20081230.tsv

Output files taht I am looking for is
2008.gz
2007.gz, etc.

Thank you.
System ProgrammingPHPPerl

Avatar of undefined
Last Comment
Andys1

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ozo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Andys1

Ozo thanks for this, but this program puts only one file in the zip.
For eg.
2007.gz should contain zip of
20070330.tsv
20070427.tsv
20070531.tsv
20070629.tsv
Similarly 2008.gz should contain zip of
20080930.tsv
20081031.tsv
20081128.tsv

Let me know if the question is still unclear. Thanks
ASKER
Andys1

Ozo, Now using it in the followin way.

#!/bin/perl
@y{map/^(\d{4})/,<*.txt>}=();
system "tar -cvf $_.tar $_*.txt" for keys %y;

Thanks for your input. You deserve all the points!
Your help has saved me hundreds of hours of internet surfing.
fblack61