Reputation: 1
I have a requirement where I need to rename a couple of filenames to a fixed filename every week.
To explain better, each week I receive 3 files in the format :
File_ABC_20160822.TXT.pgp
File_DEF_20160822.TXT.pgp
File_GHI_20160822.TXT.pgp
I need to run a small script to rename the files to :
File_ABC.dat
File_DEF.dat
File_GHI.dat
without deleting the original files, since we have to keep a log of delivered files.
The issue is that since the files come with a new date suffix each week, the script would have to pick current system date in YYYYMMDD format.
Upvotes: 0
Views: 278
Reputation: 41987
You can loop over the files names use bash
parameter expansion to get the desired name while renaming:
for f in File_*_*.TXT.pgp; do echo cp -i "$f" "${f%_*}.dat"; done
The above will do a Dry-run, for actual action, remove echo
:
for f in File_*_*.TXT.pgp; do cp -i "$f" "${f%_*}.dat"; done
Upvotes: 1