LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2008, 06:11 PM   #1
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Rep: Reputation: 15
Shell Script / awk / perl Question


Hello guys, could anyone help me please for the following...I have a large DB and it contains large amount of users.

From user data it contains such text as:

dn: uid=ALEX, ou=consumer,o=alex.com
cuserstatus: 0
canswer: hola
cquestion: What is your favorite food?
uid: alex
clinkid:alex

.
.
.

What I am looking to print all uid's corresponding with ou=consumer and it's clinkid's value.

Could someone share with me a script for it please ?


Thank you very much
 
Old 06-24-2008, 06:48 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Something like
Code:
awk -F':' '/(uid:|clinkid:)/ {print $2}' inputtextfile
?

Last edited by unSpawn; 06-24-2008 at 06:55 PM. Reason: (...)
 
Old 06-24-2008, 07:05 PM   #3
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by unSpawn View Post
Something like
Code:
awk -F':' '/(uid:|clinkid:)/ {print $2}' inputtextfile
?
I actuall tried this but it prints everyting such as:

CVA111111
34D9758248E55BD
CVA222222
34D9758248E45BD
CVA333333
.
.
.

and when I did the ldapsearch they contain all the ou's ...so the pattern seems did not match...

What I mean is, in below info, it should print uid's only that has ou=consumer and it's clinkid below it...

dn: uid=ALEX, ou=consumer,o=alex.com
cuserstatus: 0
canswer: hola
cquestion: What is your favorite food?
uid: alex
clinkid:alex


I am actually looking at a specific information...Would you have any idea why it does this ?

Thanks much...

Last edited by cmontr; 06-24-2008 at 07:08 PM.
 
Old 06-24-2008, 07:15 PM   #4
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by cmontr View Post
I actuall tried this but it prints everyting such as:

CVA111111
34D9758248E55BD
CVA222222
34D9758248E45BD
CVA333333
.
.
.

and when I did the ldapsearch they contain all the ou's ...so the pattern seems did not match...

What I mean is, in below info, it should print uid's only that has ou=consumer and it's clinkid below it...

dn: uid=ALEX, ou=consumer,o=alex.com
cuserstatus: 0
canswer: hola
cquestion: What is your favorite food?
uid: alex
clinkid:alex


I am actually looking at a specific information...Would you have any idea why it does this ?

Thanks much...
sorry if I confused

Last edited by cmontr; 06-24-2008 at 07:16 PM.
 
Old 06-24-2008, 07:37 PM   #5
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
do you think ldapsearch would be a better idea?

such like...but it didnt work so far...

while read UID
do ldapsearch -L -h localhost -p 5555 -D "uid=ab,ou=abadmin,o=alex.com" -w passwd -b o=alex.com -s sub uid=$UID clinkid
done <input.ldif >output.txt
 
Old 06-24-2008, 08:22 PM   #6
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by cmontr View Post
do you think ldapsearch would be a better idea?

such like...but it didnt work so far...

while read UID
do ldapsearch -L -h localhost -p 5555 -D "uid=ab,ou=abadmin,o=alex.com" -w passwd -b o=alex.com -s sub uid=$UID clinkid
done <input.ldif >output.txt

mmm I guess I am stuck...can anyone help pls ?

thnx...
 
Old 06-24-2008, 09:52 PM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
these are similar: this thread and this

after so long, you are still stuck ?
 
Old 06-24-2008, 10:10 PM   #8
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ghostdog74 View Post
these are similar: this thread and this

after so long, you are still stuck ?
sorry this has different conditions...i made it working with this but not the way I wanted...too slow too...
 
Old 06-24-2008, 10:12 PM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I think cmontr's idea to let a directory service be a directory service is the best idea. I'm not running an ldap service to I cant test his example.
Code:
sed -n '/ou=consumer/,/clinkid/{
                                 /dn: uid=/s/.*uid=\([^,]*\), .*/\1/p
                              /clinkid/s/clinkid://p
                               }' input.ldif >output.txt
Since the UID is listed twice, I don't know which value you wanted. One is in uppercase and the other in lower.

Also, if you only post one record, you could be hiding a pattern that can be used to delineate record.

For example, look at the output of "/sbin/lspci -v". Since each output record is separated by a blank line, it's possible to extract a record using a Broadcom device:
Code:
/sbin/lspci -v | sed -n '/Broadcom/,/^$/p'
03:0a.0 Network controller: Broadcom Corporation BCM4306 802.11b/g Wireless LAN Controller (rev 03)
        Subsystem: Linksys Device 0015
        Flags: bus master, fast devsel, latency 32, IRQ 18
        Memory at fddfc000 (32-bit, non-prefetchable) [size=8K]
        Kernel driver in use: b43-pci-bridge
        Kernel modules: ssb
 
Old 06-24-2008, 10:34 PM   #10
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
I think cmontr's idea to let a directory service be a directory service is the best idea. I'm not running an ldap service to I cant test his example.
Code:
sed -n '/ou=consumer/,/clinkid/{
                                 /dn: uid=/s/.*uid=\([^,]*\), .*/\1/p
                              /clinkid/s/clinkid://p
                               }' input.ldif >output.txt
Since the UID is listed twice, I don't know which value you wanted. One is in uppercase and the other in lower.

Also, if you only post one record, you could be hiding a pattern that can be used to delineate record.

For example, look at the output of "/sbin/lspci -v". Since each output record is separated by a blank line, it's possible to extract a record using a Broadcom device:
Code:
/sbin/lspci -v | sed -n '/Broadcom/,/^$/p'
03:0a.0 Network controller: Broadcom Corporation BCM4306 802.11b/g Wireless LAN Controller (rev 03)
        Subsystem: Linksys Device 0015
        Flags: bus master, fast devsel, latency 32, IRQ 18
        Memory at fddfc000 (32-bit, non-prefetchable) [size=8K]
        Kernel driver in use: b43-pci-bridge
        Kernel modules: ssb
I appreciate for the try ...It partially works ..I have done this with awl earlier...when it prints, it prints all "ou's" with the clinkid's. But I need only the ones with ou=consumer with along their clinkid's...it is a bit confusing...Please let me know if you have an idea. thanks much again.
 
Old 06-25-2008, 09:27 AM   #11
cmontr
Member
 
Registered: Sep 2007
Posts: 175

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by cmontr View Post
I appreciate for the try ...It partially works ..I have done this with awl earlier...when it prints, it prints all "ou's" with the clinkid's. But I need only the ones with ou=consumer with along their clinkid's...it is a bit confusing...Please let me know if you have an idea. thanks much again.

I tried this but it didnt bring what I needed ...any ideas someone please let me know..


awk '
/^uid:/ { dn = $0 }
/^clinkid:/ { print dn; print }' input.ldif >output.txt
 
Old 06-25-2008, 01:00 PM   #12
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
does this work (assuming each user has exactly 6 lines):
[untested]
Code:
max=`grep -c . input.txt`
i=1
while [ $i -lt $max ]
do
 dn=`sed -n "$i"p input.txt` | grep ou=consumer ]
 if [ $dn ]
 then
  uid=`expr $i + 4`; clinkid=`expr $i + 5`
#  sed -n "$uid"p input.txt
#  sed -n "$clinkid"p input.txt
  sed -n "$uid","$clinkid"p input.txt
 fi
 i=`expr $i + 6`
done
[/season to taste]

Last edited by schneidz; 06-25-2008 at 01:02 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk / perl script help cmontr Programming 3 05-22-2008 04:15 PM
calling awk commands in perl script bharatbsharma Other *NIX 3 11-02-2007 07:07 PM
awk/perl script for extract data mruknown1 Programming 3 09-11-2007 09:19 AM
awk/perl script for extract data mruknown1 Linux - Newbie 2 09-11-2007 04:42 AM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration