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

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 2950 | 回復: 11
打印 上一主題 下一主題

如何在文件的行首添加#號寫回原文件?? [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2007-11-28 10:59 |只看該作者 |倒序瀏覽
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)?

論壇徽章:
0
2 [報告]
發(fā)表于 2007-11-28 11:05 |只看該作者
cat /etc/syslog.conf | sed 's/^/#/' >>/etc/syslog.conf

論壇徽章:
0
3 [報告]
發(fā)表于 2007-11-28 11:20 |只看該作者
要求空行,不加#號,可是你都加了!

論壇徽章:
23
15-16賽季CBA聯(lián)賽之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午馬
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16賽季CBA聯(lián)賽之山東
日期:2017-12-21 16:39:1915-16賽季CBA聯(lián)賽之廣東
日期:2016-01-19 13:33:372015亞冠之山東魯能
日期:2015-10-13 09:39:062015亞冠之西悉尼流浪者
日期:2015-09-21 08:27:57
4 [報告]
發(fā)表于 2007-11-28 11:24 |只看該作者
sed '/^$/!s/^/#/' /etc/syslog.conf >>/etc/syslog.conf

論壇徽章:
0
5 [報告]
發(fā)表于 2007-11-28 11:27 |只看該作者

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

論壇徽章:
0
6 [報告]
發(fā)表于 2007-11-28 11:30 |只看該作者
還有已經(jīng)有#號的也要排除 !

論壇徽章:
0
7 [報告]
發(fā)表于 2007-11-28 11:43 |只看該作者
sed -i '/^[^#]/{h;G;/^[^#]/s/^/#/}' /etc/syslog.conf

論壇徽章:
0
8 [報告]
發(fā)表于 2007-11-28 12:23 |只看該作者
sed -i '/^[^#]/{h;G;/^[^#]/s/^/#/}' /etc/syslog.conf

可以解釋一下么?

論壇徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-03 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-04 06:20:00
9 [報告]
發(fā)表于 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 編輯 ]

論壇徽章:
0
10 [報告]
發(fā)表于 2007-11-28 13:05 |只看該作者

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


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

注:
有什么要求,最好一次提出,不要等別人寫出解答后再提新的條件
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP