extract Previous line search
hi guys i have a problem
i have a file with this format Quote:
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 |
Hi,
Is this what you are looking for: Code:
awk 'BEGIN { RS="" ; FS="\n" ; ORS="\n" ; OFS="" } {crea_date=sub(/.*, /,"",$2) ; web_date=sub(/.*, /,"",$5) ; if ( $2 == $5 ) { print $1 } }' mail.in Code:
#!/bin/bash |
Perhaps you should try first, rather than just ask.
|
Quote:
|
Hi,
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? EDIT: The code I posted can be shortened a bit, the crea_date= and web_date= parts aren't needed. This would do: Code:
awk 'BEGIN { RS="" ; FS="\n" ; ORS="\n" ; OFS="" } {sub(/.*, /,"",$2) ; sub(/.*, /,"",$5) ; if ( $2 == $5 ) { print $1 } }' mail.in |
Quote:
i think it didn't find match records the file is in a file new.txt and it's exactly like this PHP Code:
or email those were created on Wed, 14 Aug 2009 with WebMail Last Login Date: Thu, 01 Jan 1970 thx in advance man |
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. |
Hi,
Well...... 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 |
Quote:
|
Quote:
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). |
for first example i did that with druuna helpful command
Quote:
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="" } work at all. The following code: Code:
sub(/.*, /,"",$3) Code:
POP3 Last Login Date: Thu, 01 Jan 1970 03:30:00 Code:
Thu, 01 Jan 1970 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:
|
thx man i solved with great help of one of my friend
solution is Quote:
|
Hi,
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 |
Quote:
|
All times are GMT -5. The time now is 08:03 AM. |