I have following file which I am splitting into multiple files using awk script
Name of original File: RTLOG_5019_05122016110959.DAT
I want to set the name of split files as below:
RTLOG_5019_<timestmap (format: mmddyyyyhhmiss) >.DAT.
How do I achieve this? I don't want to hard-code the filename and also make filename-RTLOG_5019_05122016110959.DAT
as parameter
Following is my awk script
awk -v stamp=$(date +%Y%m%d%H%M%S) '
/^FHEAD/ {HD = $0
next
}
/^THEAD/ {if (FN) { printf "FTAIL%010d%010d" ORS, LN+2, LN > FN
close (FN)
LN = 0
}
FN = "RTLOG_5019_" stamp ".DAT" ++f
print HD > FN
}
!/^FTAIL/ {print >> FN
LN++
}
END {printf "FTAIL%010d%010d" ORS, LN+2, LN > FN
} ' RTLOG_5019_05122016110959.DAT