Skip to content

Instantly share code, notes, and snippets.

@thomedes
Last active December 21, 2015 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomedes/6261729 to your computer and use it in GitHub Desktop.
Save thomedes/6261729 to your computer and use it in GitHub Desktop.
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