亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 如何在文件的行首添加#號寫回原文件?? [打印本頁]

作者: chenbindream    時間: 2007-11-28 10:59
標(biāo)題: 如何在文件的行首添加#號寫回原文件??
cat /etc/syslog.conf

#ident        "@(#)syslog.conf        1.5        98/12/14 SMI"        /* SunOS 5.0 */
#
# Copyright (c) 1991-1998 by Sun Microsystems, Inc.
# All rights reserved.
#
# syslog configuration file.
#
# This file is processed by m4 so be careful to quote (`') names
# that match m4 reserved words.  Also, within ifdef's, arguments
# containing commas must be quoted.
#
*.err;kern.notice;auth.notice                        /dev/sysmsg
*.err;kern.debug;daemon.notice;mail.crit        /var/adm/messages

*.alert;kern.err;daemon.err                        operator
*.alert                                                root

*.emerg                                                *

# if a non-loghost machine chooses to have authentication messages
# sent to the loghost machine, un-comment out the following line:
#auth.notice                        ifdef(`LOGHOST', /var/log/authlog, @loghost)

mail.debug                        ifdef(`LOGHOST', /var/log/syslog, @loghost)

#
# non-loghost machines will use the following lines to cause "user"
# log messages to be logged locally.
#
ifdef(`LOGHOST', ,
user.err                                        /dev/sysmsg
user.err                                        /var/adm/messages
user.alert                                        `root, operator'
user.emerg                                        *
)

cp -p /etc/syslog.conf /etc/syslog.conf.orig

cat /etc/syslog.conf.orig | grep '^[ ]*[^#]'

*.err;kern.notice;auth.notice                        /dev/sysmsg
*.err;kern.debug;daemon.notice;mail.crit        /var/adm/messages
*.alert;kern.err;daemon.err                        operator
*.alert                                                root
*.emerg                                                *
mail.debug                        ifdef(`LOGHOST', /var/log/syslog, @loghost)
ifdef(`LOGHOST', ,
user.err                                        /dev/sysmsg
user.err                                        /var/adm/messages
user.alert                                        `root, operator'
user.emerg                                        *
)

把這個輸出的內(nèi)容,行首都加一個#號,并寫回原來的文件 ,如何實現(xiàn)?
作者: BLZer    時間: 2007-11-28 11:05
cat /etc/syslog.conf | sed 's/^/#/' >>/etc/syslog.conf
作者: chenbindream    時間: 2007-11-28 11:20
要求空行,不加#號,可是你都加了!
作者: ly5066113    時間: 2007-11-28 11:24
sed '/^$/!s/^/#/' /etc/syslog.conf >>/etc/syslog.conf
作者: springwind426    時間: 2007-11-28 11:27

  1. sed -i -r '/^[[:blank:]]*$/!s/^/#/'  數(shù)據(jù)文件
復(fù)制代碼

作者: chenbindream    時間: 2007-11-28 11:30
還有已經(jīng)有#號的也要排除 !
作者: BLZer    時間: 2007-11-28 11:43
sed -i '/^[^#]/{h;G;/^[^#]/s/^/#/}' /etc/syslog.conf
作者: chenbindream    時間: 2007-11-28 12:23
sed -i '/^[^#]/{h;G;/^[^#]/s/^/#/}' /etc/syslog.conf

可以解釋一下么?
作者: cjaizss    時間: 2007-11-28 13:05
awk '/^[ \t]*[^# \t]/{printf "#"}{print}'
sed -r 's/^([ \t]*[^# \t])/#\1/'
sed需要版本支持,GNU低版本sed對\t解釋并非制表符,高版本以上命令正確

[ 本帖最后由 cjaizss 于 2007-11-28 15:53 編輯 ]
作者: springwind426    時間: 2007-11-28 13:05

  1. sed -i -r '/^$/b;/^#/b;s/^/#/' /etc/syslog.conf
復(fù)制代碼


解釋:
/^$/b  如果是空行,跳過所有的后續(xù)命令
/^#/b  如果開頭是#,跳過所有的后續(xù)命令
s/^/#/ 在行首加#

注:
有什么要求,最好一次提出,不要等別人寫出解答后再提新的條件
作者: seeLnd    時間: 2007-11-28 13:37
沒錯,樓主確實是十分的謙虛,對人家的解答十分的客氣,最后還加個感嘆號,很生動,富有感情!
作者: nuclearxin    時間: 2007-11-28 15:58
[quote]原帖由 [i]springwind426[/i] 于 2007-11-28 13:05 發(fā)表 [url=http://www.72891.cn/redirect.php?goto=findpost&pid=7649395&ptid=1021710][img]http://www.72891.cn/images/common/back.gif[/img][/url]

sed -i -r '/^$/b;/^#/b;s/^/#/' /etc/syslog.conf


解釋:
/^$/b  如果是空行,跳過所有的后續(xù)命令
/^#/b  如果開頭是#,跳過所有的后續(xù)命令
s/^/#/ 在行首加#

注:
有什么要求,最好一次提出,不 ... [/quote]
學(xué)習(xí)了 頂




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2