Linux delete lines from ini-file where key has no value

Unix & Linux Asked by sunwave121 on December 21, 2020

I have a config file with different values formatted like this:


control_ip =
control_port =
control_socket = /run/tipper.sock
control_pass =

Now I just want to delete the lines that have no value after =, of course without deleting the [Global] section header.

One Answer

sed '/=s*$/d' infile


sed '/=[[:blank:]]*$/d' infile

delete those lines that ends with = followed by zero-or-more whitespaces.

Using awk and preserve the empty lines:

awk -F'[=t ]' '$NF!="" || /^$/' infile


awk -F'=[[:blank:]]*' '$NF!="" || /^$/' infile

Correct answer by αғsнιη on December 21, 2020

Add your own answers!

Related Questions

kdevtmpfsi process is using 100% CPU, restarting on kill

1  Asked on December 29, 2021 by syed-tahoor-ali


cannot find -luuid error make

2  Asked on December 26, 2021 by belmer1416


Can’t start sxhkd as a systemd service

1  Asked on December 26, 2021


How can I run sox as a service?

0  Asked on December 26, 2021


how can extract single character before the number in a string

4  Asked on December 26, 2021 by nas-ahmet


Add border arond text in pdf

0  Asked on December 26, 2021 by kalpesh-bhoj


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP