Skip to content

Instantly share code, notes, and snippets.

@double16
Created February 7, 2020 16:36
Show Gist options
  • Save double16/f8e532076812f0ba30661b839a242808 to your computer and use it in GitHub Desktop.
Save double16/f8e532076812f0ba30661b839a242808 to your computer and use it in GitHub Desktop.
ini.sed
# this will convert the ini data into this flat format:
#
# owner|name|John Doe
# owner|organization|Acme Widgets Inc.
# database|server|192.0.2.62
# database|port|143
# database|file|payroll.dat
# Configuration bindings found outside any section are given to
# to the default section.
1 {
x
s/^/default/
x
}
# Lines starting with a #-character are comments.
/#/n
# Sections are unpacked and stored in the hold space.
/\[/ {
s/\[\(.*\)\]/\1/
x
b
}
# Bindings are unpacked and decorated with the section
# they belong to, before being printed.
/=/ {
s/^[[:space:]]*//
s/[[:space:]]*=[[:space:]]*/|/
G
s/\(.*\)\n\(.*\)/\2|\1/
p
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment