Skip to main content
added 411 characters in body
Source Link
lynxlynxlynx
  • 3.4k
  • 1
  • 18
  • 23

Try this:

for file in *.gz; do
  gunzip -c "$file" > "${file/.DAT*/.DAT}"
done

The approach uses gunzip's option to output the uncompressed stream to standard output (-c), so we can redirect it to another file, without a second renaming call. The renaming is done on the filename variable itself, using bash substitution (match any globbing pattern .DAT* and replace it with .DAT). The loop itself just iterates over files in the current directory with names ending with .gz.

Try this:

for file in *.gz; do
  gunzip -c "$file" > "${file/.DAT*/.DAT}"
done

Try this:

for file in *.gz; do
  gunzip -c "$file" > "${file/.DAT*/.DAT}"
done

The approach uses gunzip's option to output the uncompressed stream to standard output (-c), so we can redirect it to another file, without a second renaming call. The renaming is done on the filename variable itself, using bash substitution (match any globbing pattern .DAT* and replace it with .DAT). The loop itself just iterates over files in the current directory with names ending with .gz.

Source Link
lynxlynxlynx
  • 3.4k
  • 1
  • 18
  • 23

Try this:

for file in *.gz; do
  gunzip -c "$file" > "${file/.DAT*/.DAT}"
done