linux - 在bash中解析conf文件

标签 linux bash awk sed grep

这是我的配置文件

#comment 1
--longoption1

#comment 2
--longoption2

#comment 3
-s   

#comment 4
--longoption4

我想编写一个 bash 脚本来读取这个 .conf 文件,跳过注释并像这样序列化命令行选项。

./binary --longoption1 --longoption2 -s --longoption4

最佳答案

正在处理this post on sed ,您只需将 sed 的输出通过管道传输到 xargs:

sed -e 's/#.*$//' -e '/^$/d' inputFile | xargs ./binary

正如 Wiimm 指出的那样,xargs 可能对大量参数很挑剔,并且可能会将其分解为对 binary 的多次调用。直接使用 sed 可能会更好:

./binary $(sed -e 's/#.*$//' -e '/^$/d' inputFile)

关于linux - 在bash中解析conf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56727707/

相关文章:

linux - 从文件中获取信息shell脚本linux grep命令

linux - 如何使用 yocto 食谱为 "configure"提供选项?

linux - 使用 Linux 比较两个不同的 url

linux - 如何获得过去一小时左右在我的 Linux 机器上运行的进程列表?

linux - 在/dev/shm 的子目录中创建共享内存时,shm_open() 失败并返回 EINVAL

bash - 以编程方式打开 gnome 终端并在执行 bashrc 后执行命令

python - 如何通过shell脚本编辑XML文件来更改所有数字,其中原始点除以1.3?

linux - Bash 脚本 : Read a file and process it

awk - 查找特定行中数字的平均值

linux - 从文本文件中删除奇数行或偶数行