DEV Community

Discussion on: What have you learned this week?

Collapse
 
hwolfe71 profile image
Herb Wolfe

I found a cool trick using 7zip, to extract a file from an archive, and output it to a custom filename.

I do data processing, and for one particular client, there are multiple file layouts, but basically get named either templatea.txt or templateb.txt. The data comes in as a gzipped file with a very long name. I unzip the file and rename it to either templatea.txt or templateb.txt. I decided to see if I could extract the file and rename it in one step. The first google result, superuser.com/questions/558396/aut... , gave me the answer I was looking for.

For my case, at least, the command ends up being:

7z e *.gz -so > templatea.txt

The 'e' is for extract, '-so' indicates that it should be redirected to standard out, and then I redirect it with '> templatea.txt' into the appropriate file name.

I will probably make this a batch script for now, as I have several small batch scripts like this.