Skip to content

Instantly share code, notes, and snippets.

@thomedes thomedes/ini.sed
Last active Dec 21, 2015

What would you like to do?
sed one-liners to deal with .ini / .conf files
# Get all sections from .INI file
sed -n 's/^[ \t]*\[\(.*\)\].*/\1/p' /etc/samba/smb.conf
# Get all values of given section in a clean key=value form
section=global; sed -n '/^[ \t]*\['"$section"'\]/,/^[ \]t*\[/s/^[ \t]*\([^;#\[][^ \t]*\)[ \t]*=[ \t]*\(.*\)/\1=\2/p' /etc/samba/smb.conf
# Get a specific value for a given key and section
section=global; key=workgroup; sed -n '/^[ \t]*\['"$section"'\]/,/^[ \]t*\[/s/^[ \t]*'"$key"'[ \t]*=[ \t]*\(.*\)/\1/p' /etc/samba/smb.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.