I want to process cron file with the time and cron entry into different columns of DB.
cat root | awk '{print $1, $2, $3, $4, $5, $6}'
47 * * * * string=`find somefile`; echo $string > success.txt 2> err.txt
It is easy to awk the first 5 placeholders of the cron using awk. But how do I select the actual cron entry?
In the above example I want to select every thing from “string” to “$string”
I do also want to select the standard and error out file paths. i.e. success.txt and err.txt
update:
awk '{print $NF}'
The above works for the last variable, but the following does not to find the second-last.
awk '{print $NF-2}'
A simple approach to get rid of the initial fields is to use
cut:I believe this requires the GNU version of cut, as the
--complementflag is an extension.I’d use awk to split the rest into fields:
Note that this approach involves a few assumptions: