I have following file which I am splitting into multiple files using awk scriptName of original File: RTLOG_5019_05122016110959.DATI 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 parameterFollowing is my awk scriptawk -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
How to extract part of filename in awk script
awk