当前位置: 首页 > news >正文

Linux去除注释和空行

平时查看某些配置文件的时,我们会发现有很多注释(如:"#"开头的行),中间还有很多空行,看起来非常费劲,所以在这里总结下如何去除注释和空行的方法。

举例说明
这里选个简单点的文件,来演示下效果,我们可以看到一些空行和注释。
在这里插入图片描述

rdb-save-incremental-fsync yes# Redis LFU eviction (see maxmemory setting) can be tuned. However it is a good
# idea to start with the default settings and only change them after investigating
# how to improve the performances and how the keys LFU change over time, which
# is possible to inspect via the OBJECT FREQ command.
#
# There are two tunable parameters in the Redis LFU implementation: the
# counter logarithm factor and the counter decay time. It is important to
# understand what the two parameters mean before changing them.
#
# The LFU counter is just 8 bits per key, it's maximum value is 255, so Redis
# uses a probabilistic increment with logarithmic behavior. Given the value
# of the old counter, when a key is accessed, the counter is incremented in
# this way:
#
# 1. A random number R between 0 and 1 is extracted.
# 2. A probability P is calculated as 1/(old_value*lfu_log_factor+1).
# 3. The counter is incremented only if R < P.
#
# The default lfu-log-factor is 10. This is a table of how the frequency
# counter changes with a different number of accesses with different
# logarithmic factors:
#
# +--------+------------+------------+------------+------------+------------+
# | factor | 100 hits   | 1000 hits  | 100K hits  | 1M hits    | 10M hits   |
# +--------+------------+------------+------------+------------+------------+
# | 0      | 104        | 255        | 255        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 1      | 18         | 49         | 255        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 10     | 10         | 18         | 142        | 255        | 255        |
# +--------+------------+------------+------------+------------+------------+
# | 100    | 8          | 11         | 49         | 143        | 255        |
# +--------+------------+------------+------------+------------+------------+
#
# NOTE: The above table was obtained by running the following commands:
#

去除注释和空行的命令
使用 tr命令

grep -v "#" /etc/yum.conf |tr -s '\n'

效果
在这里插入图片描述

使用 sed命令

grep -v "#" /etc/yum.conf|sed '/^$/d'

效果和上面一样,这里就不继续贴图了。

使用 awk命令

grep -v "#" /etc/yum.conf |awk '{if($0!="")print}'

使用 grep命令

grep -v "#" /etc/yum.conf |grep -v "^$"
http://www.lryc.cn/news/504855.html

相关文章:

  • Elasticsearch 7.x入门学习-Spring Data Elasticsearch框架
  • 网络层IP协议(TCP)
  • 计算机视觉中的边缘检测算法
  • js 常用扩展方法总结+应用
  • 数据结构---图(Graph)
  • 前端解析超图的iserver xml
  • LocalForage 使用指南:统一管理 LocalStorage、WebSQL 和 IndexedDB
  • 代码随想录算法训练营第五天-哈希-242.有效的字母异位词
  • 学习maven(maven 项目模块化,继承,聚合)
  • KDD 2025预讲会:10位一作的论文分享与话题思辨|12月18日全天直播
  • 掌握特征提取:机器学习中的 PCA、t-SNE 和 LDA模型
  • JAVA基础:注释
  • 从源码构建安装Landoop kafka-connect-ui
  • 【自动驾驶】Ubuntu22.04源码安装Autoware Core/Universe
  • 使用Nexus3搭建npm私有仓库
  • OpenHarmony和OpenVela的技术创新以及两者对比
  • 【LeetCode每日一题】Leetcode 1071.字符串的最大公因子
  • 《C++:计算机视觉图像识别与目标检测算法优化的利器》
  • 大模型的构建与部署(2)——数据清洗
  • 试题转excel;word转excel;大风车excel
  • 微信小程序webview和小程序通讯
  • ChatGPT大模型 创作高质量文案的使用教程和案例
  • Vue Web开发(八)
  • element-ui实现table表格的嵌套(table表格嵌套)功能实现
  • 【考前预习】4.计算机网络—网络层
  • 【java】MDC
  • Android 好的开源库
  • Go 语言结构
  • 【漆学军】MT5几个重要类库的使用例子
  • 在 Ubuntu 24.04.1 LTS (WSL) 中使用 openssl 生成 keybox.xml