I have a file that has entries in key: value
format like the below:
cat data.txt
name: 'tom'
tom_age: '31'
status_tom_mar: 'yes'
school: 'anne'
fd_year_anne: '1987'
name: 'hmz'
hmz_age: '21'
status_hmz_mar: 'no'
school: 'svp'
fd_year_svp: '1982'
name: 'toli'
toli_age: '41'
and likewise ...
I need to find and print only those key: value
that have duplicate keys as a single entry.
The below code gets me the duplicate keys
cat data.txt | awk '{ print $1 }' | sort | uniq -d
name:
school:
However, I want the output where I wish to concatenate the values of duplicate keys in one line.
Expected output:
name: ['tom', 'hmz', 'toli']
school: ['anne', 'svp']
tom_age: '31'
status_tom_mar: 'yes'
fd_year_anne: '1987'
hmz_age: '21'
status_hmz_mar: 'no'
fd_year_svp: '1982'
toli_age: '41'
Can you please suggest?
<name>_age
,status_<name>_mar
andfd_year_<school>
cry out for a different record structur.