AnswerBun.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!

Related Questions

How to expand “word” in bash? Not talking about file wildcards

2  Asked on October 31, 2021 by luis-santos

     

Parse a string using keywords

7  Asked on October 31, 2021 by beaker

       

Why does the command a-=2 fail?

4  Asked on October 31, 2021 by tmpbin

   

Shell dropping every other character of input

3  Asked on October 31, 2021 by michael-davis

         

Out of memory, but swap available

1  Asked on October 31, 2021

       

How can I display list of files in a directory?

4  Asked on October 31, 2021 by brocharvey

   

Booting from ISO suddenly stopped working

0  Asked on October 31, 2021 by ajgringo619

       

Does Pulseaudio leak memory?

2  Asked on October 31, 2021

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP