Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
first@xyz.com
Creation Date: Wed, 20 Jan 2009
POP3 Last Login Date: Thu, 01 Jan 1970
IMAP Last Login Date: Thu, 01 Jan 1970
WebMail Last Login Date: Tue, 10 Mar 2010
first1@xyz.com
Creation Date: Wed, 3 Jan 2009
POP3 Last Login Date: Thu, 01 Jan 1970
IMAP Last Login Date: Thu, 01 Jan 1970
WebMail Last Login Date: Tue, 12 Mar 2010
first2@xyz.com
Creation Date: Wed, 14 Aug 2009
POP3 Last Login Date: Thu, 01 Jan 1970
IMAP Last Login Date: Thu, 01 Jan 1970
WebMail Last Login Date: Tue, 10 Mar 2010
first3@xyz.com
Creation Date: Wed, 22 Aug 2009
POP3 Last Login Date: Thu, 01 Jan 1970
IMAP Last Login Date: Thu, 01 Jan 1970
WebMail Last Login Date: Tue, 10 Mar 2010
first4@xyz.com
Creation Date: Wed, 14 Aug 2009
POP3 Last Login Date: Thu, 01 Jan 1970
IMAP Last Login Date: Thu, 01 Jan 1970
WebMail Last Login Date: Wed, 14 Aug 2009
.
.
.
.
.
.
.
this file contain 3000 records
i want to extract only emails like first@xyz.com those were created on Wed, 14 Aug 2009 or their creation date is
Creation Date: Wed, 14 Aug 2009
and is there any solution to find emails their creation date is
Wed, 14 Aug 2009
and their last WebMail Last Login Date is same ??
for example in this sample we should just extract this email first4@xyz.com
First: WHAT did not work, WHAT is the error you are seeing (if any). Please provide input we can work with!
As in your other thread, it does work on my side.
Is the input file a normal text file?
thx man for your help no it didn't give any errors
i think it didn't find match records
the file is in a file new.txt
and it's exactly like this
PHP Code:
first1@xyz.com Creation Date: Wed, 14 Aug 2009 15:08:01 POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00 IMAP Last Login Date: Thu, 01 Jan 1970 03:30:00 WebMail Last Login Date: Tue, 13 Mar 2012 15:23:20 first2@xyz.com Creation Date: Thu, 19 Jan 2012 21:24:26 POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00 IMAP Last Login Date: Thu, 01 Jan 1970 03:30:00 WebMail Last Login Date: Fri, 16 Mar 2012 07:34:53 first3@xyz.com Creation Date: Wed, 14 Aug 2009 18:19:41 POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00 IMAP Last Login Date: Thu, 01 Jan 1970 03:30:00 WebMail Last Login Date: Sat, 17 Mar 2012 09:52:26 first4@xyz.com Creation Date: Tue, 17 Jan 2012 14:29:31 POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00 IMAP Last Login Date: Thu, 01 Jan 1970 03:30:00 WebMail Last Login Date: Wed, 07 Mar 2012 00:00:03 first5@xyz.com Creation Date: Tue, 17 Jan 2012 18:09:03 POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00 IMAP Last Login Date: Thu, 01 Jan 1970 03:30:00 WebMail Last Login Date: Sat, 17 Mar 2012 10:05:03
i need emails those have Creation Date on "Wed, 14 Aug 2009" and have same WebMail Last Login Date POP3 Last Login Date on Thu, 01 Jan 1970
or email those were created on Wed, 14 Aug 2009 with WebMail Last Login Date: Thu, 01 Jan 1970
Nice code, druuna! The problem is that there is a trailing blank space after the date in the last line, so that the expression $2 == $5 is not true anymore.
@mmhs: as syg00 pointed out, you should show some effort and try to solve the issue by yourself. Post the code you've written so far and ask help when you're at a stumbling point. It is not clear if you have some experience in awk programming or you simply leech the suggested code and expect others modify it until you reach your result. That's not a good attitude.
You need to be precise when giving information we need to work with. The example you posted in your first post doesn't come close to what you posted in post #6
The solution I posted in post #2 will not work on the file posted in post #6
Nice code, druuna! The problem is that there is a trailing blank space after the date in the last line, so that the expression $2 == $5 is not true anymore.
@mmhs: as syg00 pointed out, you should show some effort and try to solve the issue by yourself. Post the code you've written so far and ask help when you're at a stumbling point. It is not clear if you have some experience in awk programming or you simply leech the suggested code and expect others modify it until you reach your result. That's not a good attitude.
i tried many times i exctarct many informations like find the line number of those person have creation date but none of them give my last result i tried many times
i tried many times i exctarct many informations like find the line number of those person have creation date but none of them give my last result i tried many times
I believe it. Therefore, my advice is to post what you've tried, so that we can understand your level of knowledge and help you to correct your mistakes. You'll learn more this way, than trying a new and maybe completely different solution, won't you?
Regarding the code suggested by druuna, you could try to modify it to match exactly your requirement, given that in your first example there is an extra blank space at the end of the last line that breaks the algorithm (as I already pointed out in post #7).
my another problem is im not very familiar with awk i read this tutorial http://www.grymoire.com/Unix/Awk.html
but i didn't understand how can i fix it
Well the first issue will be that the solution for how to break up the file:
Code:
BEGIN { RS="" ; FS="\n" ; ORS="\n" ; OFS="" }
The above was provided to you based on the first set of data you sent but as that does not have the same format as the second set and possibly the 'main' file I am guessing it will not
work at all.
The following code:
Code:
sub(/.*, /,"",$3)
This is a regex saying to remove everything up until you encounter a comma and a space. If we assume that the previous step did actually work then it would mean the following:
Code:
POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00
# now looks like
01 Jan 1970 03:30:00
As you can clearly see, this will never equal:
Code:
Thu, 01 Jan 1970
a) It has a comma in it
b) It does not have the time code
Hence ... it is not equal
Finally, you have no variable in awk called '$', so when you say '$$' it will throw an error. I believe you are trying to say a boolean 'and' which would be '&&'
To finish, you will need to provide correctly formatted data and word your requirement better as I was not able to follow the previous statement:
Quote:
i need emails those have Creation Date on "Wed, 14 Aug 2009" and have same WebMail Last Login Date POP3 Last Login Date on Thu, 01 Jan 1970
or email those were created on Wed, 14 Aug 2009 with WebMail Last Login Date: Thu, 01 Jan 1970
The only part I can follow here is that the creation date should contain "Wed, 14 Aug 2009".
thx man i solved with great help of one of my friend
solution is
Quote:
awk '/@/{m=$0;p=0}/Creation Date: Wed, 14 Aug 2009/{p++}/POP3 Last Login Date: Thu, 01 Jan 1970/{p++}/WebMail Last Login Date: Thu, 01 Jan 1970/{p++}p==3{print m}' file
it was interesting i want to learn awk fully thx for your help here is one of the best linux forum with a good group of expret moderators thx thx thx
Glad to read you have a solution that works, but....
The posted solution does not work when using the sets of sample data you posted in this thread. The reason: There is no record that meets all the criteria. The second set (post #6) misses an entry like this:
Code:
first6@xyz.com
Creation Date: Wed, 14 Aug 2009 15:08:01
POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00
IMAP Last Login Date: Thu, 01 Jan 1970 03:30:00
WebMail Last Login Date: Thu, 01 Jan 1970 15:23:20
Posting this so others that stumble upon this thread won't get too confused
Glad to read you have a solution that works, but....
The posted solution does not work when using the sets of sample data you posted in this thread. The reason: There is no record that meets all the criteria. The second set (post #6) misses an entry like this:
Code:
first6@xyz.com
Creation Date: Wed, 14 Aug 2009 15:08:01
POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00
IMAP Last Login Date: Thu, 01 Jan 1970 03:30:00
WebMail Last Login Date: Thu, 01 Jan 1970 15:23:20
Posting this so others that stumble upon this thread won't get too confused
thx thx thx druuna yes you right the sets of sample which i posted didn't have a record likeyour sample but i said in my first post it was just 5 records of 3000 records anyway thx for your great help man
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.