我想grep
行以#
或#*
或number
或#number
開頭。換句話說,我希望從cron命令開始到結束爲止。我不需要crontab頭。 這裏是crontab文件:cron模式匹配
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd/&& run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.daily)
47 6 * * 7 root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.weekly)
52 6 1 * * root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.monthly)
#*/56 * * * * root bash /media/data/minutely.sh
#20 * * * * root bash /media/data/hourly.sh
#* * * * * root bash /media/data/looping.sh
* * * * * root bash /media/data/looping2.sh
20 * * * * root bash /media/data/hourly2.sh
而我想要的是:
17 * * * * root cd/&& run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.daily)
47 6 * * 7 root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.weekly)
52 6 1 * * root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.monthly)
#*/56 * * * * root bash /media/data/minutely.sh
#20 * * * * root bash /media/data/hourly.sh
#* * * * * root bash /media/data/looping.sh
* * * * * root bash /media/data/looping2.sh
20 * * * * root bash /media/data/hourly2.sh
.
.
.
.
#until end of line
我已經嘗試:
cat /etc/crontab | grep '^[^#0-9]'
但它給我的輸出:
17 * * * * root cd/&& run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.daily)
47 6 * * 7 root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.weekly)
52 6 1 * * root test -x /usr/sbin/anacron || (cd/&& run-parts --report /etc/cron.monthly)
如何才能grep只能拍我已經在上面解釋過了嗎? 對不起,英語不好。
使用,而不是'^ [#0-9]' – hjpotter92 2014-10-11 13:41:22
對不起,先生,我有嘗試,但輸出仍給我的標題(從'#/ etc/crontab'直到'#沒有其他crontabs做.') – 2014-10-11 13:43:16