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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions and awk

Status
Not open for further replies.

jimmy80

Programmer
May 7, 2003
13
0
0
GB
I'm having a slight problem trying to extract a date field from a text file - any hope someone could help me out!?
I have a input file from which I am trying to extract only the date field from each line - the problem is the date field is not always in the same column - sometimes it is in the thired and other times it is in the fourth column - is there a way I can use a regular expression to extract only the date field using awk? The date field is in the format yyyy-mm-dd

Thanks for your help!
Jimmy
 
Hi,
Try this :

{
if ($3 ~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/)
print $3
else
print $4
}


Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top