TransWikia.com

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:

[Global]

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

or

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

or

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

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

Add your own answers!

Ask a Question

Get help from others!

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