xbox360dp
asked on
Rename file based on contents in the file?
Gurus,
I have a request to rename a file based on the contents inside that file.
Example:
Filename: -.log
Contents:
Date of report: 2015-08-05 19:50:31 -0400
Configuration: Attribute Definition
Job ID: 9988
Transfer file: msc_attributedef_201508051 64651.csv
Line count: 2
Lines ok: -
Lines not ok: -
I need a script that will rename the -.log file to msc_attributedef_201508051 64651.log. Which is the Transfer file name inside that file.
I have a request to rename a file based on the contents inside that file.
Example:
Filename: -.log
Contents:
Date of report: 2015-08-05 19:50:31 -0400
Configuration: Attribute Definition
Job ID: 9988
Transfer file: msc_attributedef_201508051
Line count: 2
Lines ok: -
Lines not ok: -
I need a script that will rename the -.log file to msc_attributedef_201508051
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here was what I was coming up with while the others were posting...
I figured you might want to perform this change for more than one file.
perl -ne 'm/^Transfer file: (.+)\./ and close(ARGV) and rename($ARGV, "$1.log")' -.log xxx.log xxy.log
I figured you might want to perform this change for more than one file.
Open in new window