Last active
December 21, 2015 06:08
-
-
Save thomedes/6261729 to your computer and use it in GitHub Desktop.
sed one-liners to deal with .ini / .conf files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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