need some awk help to filter a file and sort into correct format
example file
uid=userA
gid=1000
homedirectory=/home/userA
uid=userB
homedirectory=/home/userA
gid=1000
you see the series gid/homedirectory is sometimes twisted.
wanted output format is
uid;gid;homedirectory
userA;1000;/home/userA
userB;1000;/home/userB
CodePudding user response:
mawk -F= ' function __() { printf("%s;%s;%s%*s", _["u"], _["g"], _["h"], split(___,_), RS) } { if (NF) { _[sprintf("%c",$___)] = $NF } else __() } END { __() } '
userA;1000;/home/userA
userB;1000;/home/userB