Read certain key from certain section of ini file (sed/awk ?)
问题 I need to retrieve the value of a key from an ini file with typical structure: [abcd] key1=a key2=b [efgh] key1=c key2=d [hijk] key1=e key2=f with key names repeated in different sections, and no consistant naming/order of sections. How could I find key1 from efgh? If I grep then I'll find all key1's (and I don't know the order of the sections). I suspect sed or awk can do this but I can't find it... 回答1: This could be a start: awk -F'=' -v section="[efgh]" -v k="key1" ' $0==section{ f=1;