Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing dates

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
Hey all, I would have tried to do this in sed but the file is a bit large...

I have a CSV file (Asterisk) and I need to parse out a range of dates from it...

"","8605551212","1223","outbound","""RECEPTION"" <8605551212>","SIP/1201-08f42e80","SIP/1223-08e75548","Dial","SIP/1223|25|tr","2006-07-27 13:03:49",,"2006-07-27 13:04:10",21,0,"NO ANSWER","DOCUMENTATION"


"","8605551212","1223","outbound","""RECEPTION"" <8605551212>","SIP/1201-08f42e80","SIP/1223-08e75548","Dial","SIP/1223|25|tr","2006-07-27 13:03:49",,"2006-08-06 13:04:10",21,0,"NO ANSWER","DOCUMENTATION"

Normally I would first view the file (more filename) then get to a specific date, get a line count then wc -l it and print out those lines in sed...

sed -n '$LINE__NUMBER_BEGIN,LINE_NUMBER_ENDp' filename >> parsed

But I'm sure an awkpimp has a better solution....
 
Hi

That [tt]sed[/tt] oneliner's [tt]awk[/tt] equivalent is
Code:
awk '{NR>=LINE__NUMBER_BEGIN && NR<=LINE_NUMBER_END}' filename >> parsed
But for your date question seems to need
Code:
awk '{gsub(/"/,"",$10)} $10>="[green][i]stardate[/i][/green]" && $10<="[green][i]enddate[/i][/green]"' filename

Feherke.
 
Thanks... Didn't seem to work though. I think I'm going to bite the bullet, open up the 6 files and do it manually
 
Hi

Sorry, I copy&pasted wrong code. Should be :
Code:
awk [red]-F,[/red] '{gsub(/"/,"",$10)} $10>="[green][i]stardate[/i][/green]" && $10<="[green][i]enddate[/i][/green]"' filename

Feherke.
 
Thanks feherke... You should start a write up on AWK and handy onliners and throw it on your page
 
Perhaps you and PHV should get together and write something like an O'Reilly book. Not kidding you or trying to inflate egos here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top