iniq is a simple INI file reader for the command line. It queries an INI file based on the path <section><separator><key> and allows use of custom separators in the file and formatting of the output. Sections inherit keys from a special DEFAULT section unless the -D flag is used. See below for examples.
RPM package available from copr. 
Install with:
dnf copr enable jcrd/iniq
dnf install iniq
usage: iniq [options] [FILE]
With no FILE, read standard input.
options:
-h Show help message
-q Suppress error messages
-d Include DEFAULT section in section list
-D Disable inheriting of DEFAULT section
-s SEPS Key/value pair separators (default: '=:')
-m Parse multi-line entries
-c Combine sections with the same name
-P SEP Path separator character (default: '.')
-p PATH Path specifying sections/keys to print
-n Get number of sections with the name given in PATH
-i NUM Index of section in PATH
-f FORMAT Print output according to FORMAT
where %s = section, %k = key, %v = value
-o Output sections, keys, and values
-v Show version
Given the configuration file example.conf:
in_section=false
[DEFAULT]
default=true
[section1]
key1=value1
[example.com]
key2=value2
Print sections in a file:
$ iniq example.conf
section1
example.com
Include DEFAULT section:
$ iniq -d example.conf
DEFAULT
section1
example.com
Print sectionless key/value pairs:
$ iniq -p . example.conf
in_section=false
Print sectionless keys:
$ iniq -p .. example.conf
in_section
Print value of sectionless key:
$ iniq -p .in_section example.conf
false
Print key/value pairs in section1, disabling DEFAULT:
$ iniq -D -p section1 example.conf
key1=value1
Print keys in section1, disabling DEFAULT:
$ iniq -D -p section1. example.conf
key1
Print value of key1 in section1:
$ iniq -p section1.key1 example.conf
value1
Use alternative path separator:
$ iniq -P , -p example.com,key2 example.conf
value2
Print values followed by their keys in section1, using the format %v:%k:
$ iniq -p section1 -f %v:%k example.conf
true:default
value1:key1
Print only the values in section1, using the format %v:
$ iniq -p section1 -f %v example.conf
true
value1
Escape section name containing dots:
$ iniq -D -p example\\.com example.conf
key2=value2
Output sections, keys, and values:
$ iniq -f '%k:%v' -o example.conf
section: in_section:false
section:section1 default:true key1:value1
section:example.com default:true key2:value2
Configuration files may contain sections with the same name.
Given the configuration file multi.conf:
[test]
section0=0
[test]
section1=1
Print sections:
$ iniq multi.conf
test
test
Combine sections with the same name:
$ iniq -c -p test. multi.conf
section0
section1
Get number of sections:
$ iniq -p test -n multi.conf
2
Get section by index:
$ iniq -p test. -i 1 multi.conf
section1
This project is licensed under the New BSD License (see LICENSE).
Content type
Image
Digest
Size
104.6 MB
Last updated
over 4 years ago
docker pull supplantr/iniq