Charlie Bondurant Charlie Bondurant - 7 months ago 42
Bash Question

Extracting values from a CSV-like file consisting of key=value pairs using SED

Input file:


Need to get output like:


Tried to do it like this:

sed 's/(([A-Z][a-z]+)[=](^[0-9]+)[^;])//g'

didn't return any error, but nothing happened with output file.

Please help.

sed 's/[^=]\+=\([^;]\+;\?\)/\1/g' file

In the basic regular expression syntax you should write \+, \(, \), and \? instead of +, (, ), and ? correspondingly. If you find this syntax inconvenient, you may use the extended syntax:

sed -r 's/[^=]+=([^;]+;?)/\1/g' file

The only difference between basic and extended regular expressions is in the behavior of a few characters: ?, +, parentheses, and braces ({})

If you want to modify the file in-place, use -i option. If you want to output the result into another file, use I/O redirection:

sed -r 's/[^=]+=([^;]+;?)/\1/g' file > outfile