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!

Selecting Part of a Field

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
I have a (daily) error file that looks like this:

04/28/05 10:11:07|adt_in|CL71234567|PATIENT '1234567' ALREADY DISCHARGED

Often, due to automatic processes that are running at midnight, I have thousands of these lines to look through for valid errors.

What I need is a quick ksh routine to allow me to pull, from this (date/time) sorted list, any line which has a time stamp (10:11:07 above) that is outside of the 0001-0010 time frame.

I've tried one suggestion from the Unix scripting forum - filtering with the line

Code:
awk '$2 > "00:00:10"' infile > outfile

but the field I need to check is field 1, not two and I can't figure out how to just look at the time portion of the first field and not the whole thing.

Comments greatly appreciated.

Tnx.

Tom

"My mind is like a steel whatchamacallit ...
 
#!/usr/dt/bin/dtksh

while read line
do
time=${line:9:8}
h=${line:9:2}
m=${line:12:2}
s=${line:15:2}
if [[ $h$m > 0000 && $h$m < 0011 ]]
then
print "Time is between 0001 and 0010."
fi
done < text
print $time $h $m $s


#cat text
04/28/05 10:11:07|adt_in|CL71234567|PATIENT '1234567' ALREADY DISCHARGED
 
Something like this ?
awk -F'|' '{if(split($1,dt," ")==2)if(dt[2]>"00:10:00")print}' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top