I have a file full of keys and values which I use for i18n. The file looks like this:
foo.foo=Some string
foo.bar=Some string
bar.foo=Some string
bar.bar=Some string
baz.foo=Some string
baz.bar=Some string
Using some unix tool like awk or sed, how can I filter the file so that lines beginning with the same prefix (up to the first dot) are grouped together, and groups are separated by a blank line?
The output should look like
foo.foo=Some string
foo.bar=Some string
bar.foo=Some string
bar.bar=Some string
baz.foo=Some string
baz.bar=Some string
This should do:
awk -F. '$1!=a && NR>1 {print ""} 1; {a=$1}' file
foo.foo=Some string
foo.bar=Some string
bar.foo=Some string
bar.bar=Some string
baz.foo=Some string
baz.bar=Some string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With