gzip multiple files and rename them

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have to gzip multiple files in a directory and rename them. I dont want to zip them into a single zip file. i.e.
gzip:
ABCDEPG01_20171120234905_59977
ABCDEPG02_20171120234905_59978
ABCDEPG03_20171120234905_59979
to:
ABCDEFG_DWH_ABCDEPG01_20171120234905_59977.gz
ABCDEFG_DWH_ABCDEPG02_20171120234905_59978.gz
ABCDEFG_DWH_ABCDEPG03_20171120234905_59979.gz
files gzip
add a comment |
up vote
1
down vote
favorite
I have to gzip multiple files in a directory and rename them. I dont want to zip them into a single zip file. i.e.
gzip:
ABCDEPG01_20171120234905_59977
ABCDEPG02_20171120234905_59978
ABCDEPG03_20171120234905_59979
to:
ABCDEFG_DWH_ABCDEPG01_20171120234905_59977.gz
ABCDEFG_DWH_ABCDEPG02_20171120234905_59978.gz
ABCDEFG_DWH_ABCDEPG03_20171120234905_59979.gz
files gzip
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have to gzip multiple files in a directory and rename them. I dont want to zip them into a single zip file. i.e.
gzip:
ABCDEPG01_20171120234905_59977
ABCDEPG02_20171120234905_59978
ABCDEPG03_20171120234905_59979
to:
ABCDEFG_DWH_ABCDEPG01_20171120234905_59977.gz
ABCDEFG_DWH_ABCDEPG02_20171120234905_59978.gz
ABCDEFG_DWH_ABCDEPG03_20171120234905_59979.gz
files gzip
I have to gzip multiple files in a directory and rename them. I dont want to zip them into a single zip file. i.e.
gzip:
ABCDEPG01_20171120234905_59977
ABCDEPG02_20171120234905_59978
ABCDEPG03_20171120234905_59979
to:
ABCDEFG_DWH_ABCDEPG01_20171120234905_59977.gz
ABCDEFG_DWH_ABCDEPG02_20171120234905_59978.gz
ABCDEFG_DWH_ABCDEPG03_20171120234905_59979.gz
files gzip
files gzip
edited 2 days ago
don_crissti
48.6k15129158
48.6k15129158
asked 2 days ago
Scott Mick
92
92
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
Are you just adding a prefix? Then something like this could do:
prefix=ABCDEFG_DWH_
for f in ABCDEPG*; do
gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
done
Yes, just adding a prefix. thanks!
– Scott Mick
2 days ago
@ScottMick If this solves your issue, please consider accepting the answer.
– Kusalananda
2 days ago
add a comment |
up vote
1
down vote
An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):
for name in ABCDEPG*; do
gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
done
Or in parallel with xargs (here, four parallel tasks will be spawned):
printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz --
That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):
printf '%sn' ABCDEPG* |
xargs -P 4 -I
sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh
@don_crissti/usr/bin/gzipin the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
– Kusalananda
2 days ago
1
@don_crissti But, but, everyone's using OpenBSD, suuurely?
– Kusalananda
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Are you just adding a prefix? Then something like this could do:
prefix=ABCDEFG_DWH_
for f in ABCDEPG*; do
gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
done
Yes, just adding a prefix. thanks!
– Scott Mick
2 days ago
@ScottMick If this solves your issue, please consider accepting the answer.
– Kusalananda
2 days ago
add a comment |
up vote
3
down vote
accepted
Are you just adding a prefix? Then something like this could do:
prefix=ABCDEFG_DWH_
for f in ABCDEPG*; do
gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
done
Yes, just adding a prefix. thanks!
– Scott Mick
2 days ago
@ScottMick If this solves your issue, please consider accepting the answer.
– Kusalananda
2 days ago
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Are you just adding a prefix? Then something like this could do:
prefix=ABCDEFG_DWH_
for f in ABCDEPG*; do
gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
done
Are you just adding a prefix? Then something like this could do:
prefix=ABCDEFG_DWH_
for f in ABCDEPG*; do
gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
done
answered 2 days ago
ilkkachu
53.6k781146
53.6k781146
Yes, just adding a prefix. thanks!
– Scott Mick
2 days ago
@ScottMick If this solves your issue, please consider accepting the answer.
– Kusalananda
2 days ago
add a comment |
Yes, just adding a prefix. thanks!
– Scott Mick
2 days ago
@ScottMick If this solves your issue, please consider accepting the answer.
– Kusalananda
2 days ago
Yes, just adding a prefix. thanks!
– Scott Mick
2 days ago
Yes, just adding a prefix. thanks!
– Scott Mick
2 days ago
@ScottMick If this solves your issue, please consider accepting the answer.
– Kusalananda
2 days ago
@ScottMick If this solves your issue, please consider accepting the answer.
– Kusalananda
2 days ago
add a comment |
up vote
1
down vote
An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):
for name in ABCDEPG*; do
gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
done
Or in parallel with xargs (here, four parallel tasks will be spawned):
printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz --
That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):
printf '%sn' ABCDEPG* |
xargs -P 4 -I
sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh
@don_crissti/usr/bin/gzipin the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
– Kusalananda
2 days ago
1
@don_crissti But, but, everyone's using OpenBSD, suuurely?
– Kusalananda
2 days ago
add a comment |
up vote
1
down vote
An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):
for name in ABCDEPG*; do
gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
done
Or in parallel with xargs (here, four parallel tasks will be spawned):
printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz --
That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):
printf '%sn' ABCDEPG* |
xargs -P 4 -I
sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh
@don_crissti/usr/bin/gzipin the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
– Kusalananda
2 days ago
1
@don_crissti But, but, everyone's using OpenBSD, suuurely?
– Kusalananda
2 days ago
add a comment |
up vote
1
down vote
up vote
1
down vote
An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):
for name in ABCDEPG*; do
gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
done
Or in parallel with xargs (here, four parallel tasks will be spawned):
printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz --
That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):
printf '%sn' ABCDEPG* |
xargs -P 4 -I
sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh
An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):
for name in ABCDEPG*; do
gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
done
Or in parallel with xargs (here, four parallel tasks will be spawned):
printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz --
That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):
printf '%sn' ABCDEPG* |
xargs -P 4 -I
sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh
edited 2 days ago
answered 2 days ago
Kusalananda
115k15218351
115k15218351
@don_crissti/usr/bin/gzipin the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
– Kusalananda
2 days ago
1
@don_crissti But, but, everyone's using OpenBSD, suuurely?
– Kusalananda
2 days ago
add a comment |
@don_crissti/usr/bin/gzipin the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
– Kusalananda
2 days ago
1
@don_crissti But, but, everyone's using OpenBSD, suuurely?
– Kusalananda
2 days ago
@don_crissti
/usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!– Kusalananda
2 days ago
@don_crissti
/usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!– Kusalananda
2 days ago
1
1
@don_crissti But, but, everyone's using OpenBSD, suuurely?
– Kusalananda
2 days ago
@don_crissti But, but, everyone's using OpenBSD, suuurely?
– Kusalananda
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481996%2fgzip-multiple-files-and-rename-them%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown