Linux 下去除空白行的方法

背景:
有时当进行某些配置文件的查看时,去除注释(如:"#"),但之后还会发现中间也许会有好多空行,
所以小结一下去除空行的方法。

#pwd
/usr/local/kafka/config

方法1:
#cat server.properties | grep -v ^#|uniq | tr -s '\n'
方法2:

#cat server.properties | grep -v ^#|uniq | grep -v "^$"
方法3:
#cat server.properties | grep -v ^#|uniq | awk '{if($0!="")print}'
等同于:
#cat server.properties | grep -v ^#|uniq | awk '{if(length !=0) print $0}'

方法4:
# cat server.properties | grep -v ^#|uniq | sed '/^$/d'
示例:
broker.id=1
host.name=10.19.85.149
auto.create.topics.enable=true
delete.topic.enable = true
message.max.bytes=200000000
replica.fetch.max.bytes=204857600
fetch.message.max.bytes=204857600
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=1048576000
log.dirs=/data/kafka/log
num.partitions=3
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=10.19.85.149:2181,10.19.15.103:2181,10.19.189.221:2181
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0

 

你可能感兴趣的:(Linux)