Im trying to retrieve some user for a ldif file containing some specific attribute.
The input file will look like:
# entry-id: 2
dn: uid=xxx,ou=xx,cn=xx,o=xx,c=xx,o=xx
uid: xxx
cn: Paul
SUKsoft: Windows
SUKsoft: Linux
...
# entry-id: 3
dn: uid=yyy,ou=yy,cn=yy,o=yy,c=yy,o=yy
uid: yy
cn: Jones
SUKsoft: Windows
...
# entry-id: 3
dn: uid=zzz,ou=zz,cn=zz,o=zz,c=zz,o=zz
uid: zz
cn: John
SUKsoft: Linux
...
# entry-id: 4
dn: uid=www,ou=ww,cn=ww,o=ww,c=ww,o=ww
uid: ww
cn: John2
...
# entry-id: 5
dn: uid=mmm,ou=mm,cn=mm,o=mm,c=mm,o=mm
uid: mm
cn: John3
SUKsoft: Linux
...
The result file should filter for the user with the SUKsoft: Windows attribute:
uid|cn
xx|Paul
yy|Jones
I dont have much experience with linux shell bash, i am trying to read iterate the file first to obtain suksoft and uid attributes ad then reprocess it again to compone the final file getting just the uid with the SUKsoft below:
cat 1.txt | while read line
do
egrep -w '^uid|SUKsoft' $line > output.txt
done
Now the output looks like:
uid: xxx
SUKsoft: Windows
SUKsoft: Linux
uid: yy
SUKsoft: Windows
uid: zz
SUKsoft: Linux
uid: ww
uid: mm
SUKsoft: Linux
Now i would like to process the file get the uid line ultil i have one SUKsoft: Windows and copy them to the final file.
Could you help me here please?
Thanks
Regards