LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-14-2006, 05:09 AM   #1
Sapper1729
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Rep: Reputation: 0
Help with Linux files


Hi I am very new to Linux and I need to carry out the following tasks:

I have an LDAP search that I have set to query an Open LDAP server and the results I have redirected to a log file called ldaptest.log, this all works fine.

The issue is that there is data in the file that I don't want to use as I wish to import the data into a database, an example is as follows:

---------------------------------------------------------
dn: uid=user1,ou=users,dc=domain,dc=com
mail: user1@domain.com

dn: uid=user2,ou=users,dc=domain,dc=com
mail: user2@domain.com

dn: uid=user3,ou=users,dc=domain,dc=com
mail: user3@domain.com

---------------------------------------------------------
I need to remove all the data relating to the dn: so as to just leave the email addresses, like the following:

mail: user1@domain.com
mail: user2@domain.com
mail: user3@domain.com

Can anyone tell me how I go about this, it needs to be ran as an automated event as the LDAP search will run and produce the file and then after the file has been created I need to run something to change the data in the file prior to the import.

Thanks in advance.
 
Old 08-14-2006, 05:17 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
If you're planning to run this on a Linux system, you could use grep to drop the lines that contain "dn:" like this:

Code:
cat ldaptest.log | grep -v "dn: " > ldaptest2.log
That should read ldaptest.log, then use grep to drop off the lines starting with "dn: " (the lines you wanted to, right?) and then direct the output into a file called ldaptest2.log.

I hope this is what you asked for; the above command can be easily automated, so that's not a problem. One problem could be caused by the fact that every line containing the string "dn: " will get removed, so if you happened to have a line that contains "dn: " but does not need to be removed, it still does get removed. But in this example the above command works well, if you only have "dn: ..." and "mail: ..." lines.
 
Old 08-14-2006, 05:32 AM   #3
Sapper1729
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks very much for that, I have tried this but this displays the following:
cat ldaptest2.log
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I have been trying this myself and I have used the following:

grep mail: ldaptest.log > /emailfile.log

This then displays the following:

ldaptest.log:mail: user1@domain.com
ldaptest.log:mail: user2@domain.com
ldaptest.log:mail: user3@domain.com
ldaptest.log:mail: user4@domain.com
ldaptest.log:mail: user5@domain.com
ldaptest.log:mail: user6@domain.com

So it's getting better, I guess that I need to remove the ldaptest.log:mail: part and then I'm good to go.

Thanks for helping me
 
Old 08-14-2006, 05:44 AM   #4
Sapper1729
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Original Poster
Rep: Reputation: 0
I have it sorted now, it needs to be a lower case v, so the output looks as follows:


mail: user1@domain.com

mail: user2@domain.com

mail: user3@domain.com

mail: user4@domain.com

Can I please ask if the mail: can also be removed but not the actual email address, any advice I would benefit from

Thanks
 
Old 08-14-2006, 06:23 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Code:
 cat ldaptest.log | grep -v "dn: " | sed 's/^mail: //' > emailfile.log
 
Old 08-15-2006, 07:47 AM   #6
Sapper1729
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks, work a treat

Good stuff
 
  


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
converting a doc/ppt Windows files in html files under linux env agrosu Programming 7 02-23-2006 03:07 PM
.sit files and .bin files in Linux pierre24 Linux - Newbie 2 02-02-2005 07:55 AM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 02:24 AM
win2k sees linux files... linux won't see win2k files.. please help.. what will i do? kublador Linux - Networking 1 03-24-2003 07:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:07 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