Chinaunix
标题:
如何去掉只有一个#的行
[打印本页]
作者:
pzw1985
时间:
2013-09-17 16:44
标题:
如何去掉只有一个#的行
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
# Enable IPv4, and IPv6 if supported
inet_protocols = all
# The proxy_interfaces parameter specifies the network interface
复制代码
请问,如何去只有#的行,和以“# ”开头的行,处理后的结果是这样的:
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
inet_protocols = all
谢谢!
作者:
HH106
时间:
2013-09-17 16:49
觉得08年注册的不应该问这种问题啊?
作者:
Shell_HAT
时间:
2013-09-17 16:50
sed '/^# /d; /^#$/d' urfile
复制代码
作者:
jason680
时间:
2013-09-17 17:29
回复
1#
pzw1985
How about this
# grep -vP '^#(
$
|\s)' FILE
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
inet_protocols = all
-------------------------------------
and found a bug with "\s" pattern
# grep -vP '^#\s' FILE
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
inet_protocols = all
作者:
pzw1985
时间:
2013-09-17 17:49
回复
2#
HH106
献丑了。。
那时候是因为好奇注册了下
作者:
henryele
时间:
2013-09-17 23:04
egrep '^[^#]*#[^#]*$' file
我只是练习下正则,不知道写的对不,试了些数据,貌似可行。请大神指教
作者:
pzw1985
时间:
2013-09-18 08:52
回复
3#
Shell_HAT
谢谢!^和$代表正行我没有想到。
作者:
pzw1985
时间:
2013-09-18 08:59
回复
4#
jason680
谢谢!
我man了下grep,看到-P是用的perl,效果是和-E扩展正则一样的吧。
作者:
pzw1985
时间:
2013-09-18 09:03
回复
6#
henryele
貌似不对
结果中没有不以#开头的行
作者:
blackold
时间:
2013-09-18 09:15
回复
2#
HH106
http://passport.ixpub.net/data/a ... 9_avatar_middle.jpg
作者:
blackold
时间:
2013-09-18 09:18
回复
1#
pzw1985
标题与贴子内容不符啊。
作者:
bangde32
时间:
2013-09-18 10:46
来看高手解答
作者:
linuxbrook
时间:
2013-09-18 10:52
grep -v "#" file
作者:
noshell
时间:
2013-09-18 22:24
楼主的意思是去掉 带“#” 的行,为啥 结果里还有带“#” 号的行?
我也来一个 sed -e 's/^#.*//g' -e '/^$/d' yfile
作者:
baoersc
时间:
2013-09-19 20:44
学习,冒昧的问一句:\s的作用?
作者:
pzw1985
时间:
2013-09-24 16:01
回复
15#
baoersc
应该是空格的意思
作者:
baoersc
时间:
2013-09-25 15:14
grep -v '=' file
作者:
zengbo1019
时间:
2013-10-22 11:01
awk '{if($0~/^#/)next;print}' ufile
作者:
Herowinter
时间:
2013-10-22 11:25
如果处理结果替换原文件的话我写的是这个
sed -i "/^#$\|^# /d" urfile
作者:
reyleon
时间:
2013-10-29 19:22
awk '$1!="#"'
复制代码
作者:
me09
时间:
2017-04-30 22:10
#!/bin/sh
INPUT_FILE=<conf_file_name>
while read LINE
do
case $LINE in
"#"*)
;;
*) echo $LINE
;;
esac
done <$INPUT_FILE
复制代码
去除配置文件# 号行的shell代码,本代码在 Ubuntu 17系统调试可用,不保证你使用的系统也可用。【 "#"*),有的系统或许要修改为 \#*)】
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2