Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

File name manipulation when extracting from gzip

$
0
0
Hi,

Below is the description of my problem.

I am trying to loop through the below file names sitting in the file - FileNames.txt, and trying to decompress them

FileNames.txt
Code:

20150408_MGAC_[0-9][0-9][0-9][0-9].txt.gz
20150408_MGCC_[0-9][0-9][0-9][0-9].txt.gz
20150408_MGSH_[0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].txt.gz
20150408_MGSL_[0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9].txt.gz

filename="20150408_MGAC_[0-9][0-9][0-9][0-9].txt.gz"

But when I use the below command -
Code:

gzip -c  ${filename} > ${filename%.*}
I get the output file name like this -
Code:

20150408_MGAC_[0-9][0-9][0-9][0-9].txt
How can I format the output file name to something like the below?
Code:

20150408_MGAC_1111.txt
20150408_MGCC_1111.txt
20150408_MGSH_1111_1111.txt
20150408_MGSL_1111_1111.txt

I have tried multiple options while extracting the files but I am not able to get the desired result.

Please help.

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images