Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse crontab 2

Status
Not open for further replies.

grazinggoat

Programmer
Mar 12, 2008
41
US
I have tried cut, sort and am unable to
figure a way to parse my crontab so that I get the arguments field..

1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1

I'd like strip the min,hour,day of month,day of week,
to be able to only view..

[ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1

Any thoughts?

Thanks
 
you'll get some leading whitespace but try this:

[tt]
crontab -l|awk '{if ($1!~/^#/) {$1=$2=$3=$4=$5=""; print }}'
[/tt]


HTH,

p5wizard
 
Hi

Just an off-topic curiosity, but what is the problem with [tt]cut[/tt] ?
Code:
crontab -l | cut -d' ' -f6-
Or if you have the unusual habit to use multiple spaces and/or tabs as separators :
Code:
crontab -l | tr -s ' \t' ' ' | cut -d' ' -f6-

Feherke.
 
How about:
Code:
crontab -l | awk '{print substr($0, index($0,$6)) }'
then, since it's awk...

HTH
 
Right ..Thanks.

I tried the cut ..here was my syntax:

crontab -l | cut -d' ' -f6

I ommited the hyphen on the end.
I didn't realize it would have read
to the end of line.

Thanks,
 
feherke, I find cut to be of limited use in this type of situation because there are often multiple spaces, and cut unfortunately doesn't have an option to treat multiple delimiters as one. I think that's the main reason you almost always see awk '{print $6}' (for example) used instead.

Annihilannic.
 
Hi

Annihilannic said:
feherke, I find cut to be of limited use in this type of situation because there are often multiple spaces, and cut unfortunately doesn't have an option to treat multiple delimiters as one.
I agree. ( Please note that my previous post was "off-topic curiosity", not suggestion. )

Anyway, I would not bury [tt]cut[/tt] too deep.
Code:
[blue]master #[/blue] time awk '{print$6}' < big.txt > /dev/null
real    0m2.301s
user    0m2.260s
sys     0m0.040s

[blue]master #[/blue] time cut -d' ' -f6 < big.txt > /dev/null
real    0m0.560s
user    0m0.500s
sys     0m0.050s

[blue]master #[/blue] time tr -s ' \t' ' ' < big.txt | cut -d' ' -f6 > /dev/null
real    0m0.701s
user    0m0.630s
sys     0m0.060s
Tested with [tt]gawk[/tt], GNU [tt]cut[/tt] and [tt]tr[/tt] and a 9 column data file.


Feherke.
 
Yep, I realised it was off-topic curiosity... I have also always been curious why the cut utility omitted such an obvious feature. Perhaps I should submit a patch for the GNU version... ;-) Thanks for the tr -s tip, I've never used that option...

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top