For filenames like this:
fileLoad.xml2017-12-21_10_55_53-153.txt
otherFile.xml2017-12-20-11_23_01-87899.txt
someFile.xml2017-11-30-21_00_59-1.txt
What I'm trying to accomplish with awk is to isolate the file name up through .xml and then isolate and format the timestamp for use in a csv/database.
I have the following:
NR==1 {
fn=substr(FILENAME, 0, FILENAME-5);
ts=fn;
sub(/[0-9]{4}.*$/,"",fn);
sub(/^\w+\.xml/,"",ts);
} {
printf "fn\tts"
}
I can strip off the '-' from the end, but after that I can't figure out how in awk to convert the remaining timestamp to be formatted as 2017-11-30 21:00:59.
awkwas apparently the right tool for parsing the contents of the file, but I'm trying to isolate the specific task (file) from the timestamp of when it was created as separate fields in an output csv.echo "fileLoad.xml2017-12-21_10_55_53-153.txt" | sed -r 's/.*xml//; s/-[[:digit:]]*.txt//; s/_/ /; s/_/:/g'\win regexes, GNU awk does. Also, is the first file correctly named there? It has an underscore_between the date and the time, the others have a dash-. (I'm just asking since this would be rather straightforward with GNU awk, esp. if the first file name is in error.)