1847352 Members
4406 Online
110264 Solutions
New Discussion

Format output

 
SAM_24
Frequent Advisor

Format output

Hi,

I want to remove the time fields from crontab -l output. For example

* * * * * command

I want to remove everything before command.

In place of * there'd be time specs. In command field there'd be different script name.

Any help is appreciated.

Thanks.
Never quit
5 REPLIES 5
Sundar_7
Honored Contributor

Re: Format output

May not be the most elegant way, but gets the job done :-)

crontab -l | egrep -v "^#|^$" | awk '{for(i=6;i<=NF;i++) printf("%s ",$i); printf("\n");}'
Learn What to do ,How to do and more importantly When to do ?
BONNAFOUS Jean Marc
Trusted Contributor

Re: Format output

Hi,

crontab -l|egrep -v "^#" |cut -d" " -f6


Best Regards
JMB
Si vous ne faites jamais de bétises, c'est que vous ne faites rien de difficile. Et ça c'est une grosse bétise.
Franky_1
Respected Contributor

Re: Format output

Hi,

just type

crontab -l|grep -v "^#"|awk '{print $6}'

Should do the trick

Regards

Franky
Don't worry be happy
Muthukumar_5
Honored Contributor

Re: Format output

We can do this as,
crontab -l | grep "^[ 0-9*]" | cut -d" " -f6-

It will cut all field's 6th and after

-------
Franky, marc, we will be having some more filed's after 6 there on cron too :-)

05,15,25,35,45,55 * * * * /usr/sbin/dmesg - >>/var/adm/messages

will give only /usr/sbin/dmesg in your try there.
---------

HTH.
Muthu
Easy to suggest when don't know about the problem!
Rodney Hills
Honored Contributor

Re: Format output

How about a perl one-liner:

crontab -l | perl -ne 'split("\\s+",$_,6); print $_[5]'

HTH

-- Rod Hills
There be dragons...