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

print $1 between given start and given end

Status
Not open for further replies.

madasafish

Technical User
Jul 18, 2006
78
TH
I have "week" file with $1 in a series.

Example week file


042007|27/06-21:52:35|27/06-21:52:38|27/06-21:52:41|66
032007|27/06-21:52:35|27/06-21:52:38|27/06-21:52:41|66
022007|27/06-21:52:35|27/06-21:52:38|27/06-21:52:41|66
012007|27/06-21:52:36|27/06-21:52:38|27/06-21:52:41|66
522006|27/06-21:52:36|27/06-21:52:38|27/06-21:52:41|66
512006|27/06-21:52:36|27/06-21:52:38|27/06-21:52:41|66
502006|27/06-21:52:36|27/06-21:52:38|27/06-21:52:41|66
~ $1 is the key field of interest
~ this bit cut out
082006|27/06-21:52:37|27/06-21:52:40|27/06-21:52:43|65
072006|27/06-21:52:37|27/06-21:52:40|27/06-21:52:43|65
062006|27/06-21:52:37|27/06-21:52:40|27/06-21:52:43|65
052006|27/06-21:52:37|27/06-21:52:40|27/06-21:52:43|65
042006|27/06-21:52:37|27/06-21:52:40|27/06-21:52:43|65

I want to supply a begin week and end week
and then print all weeks in order between and including the
the begin and end weeks.

Example nawk english code:
STARTWK=042006
ENDWK=042007

nawk -v startwk=$STARTWK -v endwk=$ENDWK '{
if ($1 ~ startwk)
print $1 and every other $1 up until and including endwk
}' weekfile > newfile


Madasafish














 
Like this ?
sort weekfile | nawk -F'|' -v startwk=$STARTWK -v endwk=$ENDWK '{
if($1>=startwk && $1<=endwk}print$1
}' > newfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV.
Im sure the nawk bit works it's the the sort routine.
It loses the $1 series. I believe it's due to the WEEK before the YEAR entry

Madasafish


 
OOps, sorry:
nawk -F'|' -v startwk=$STARTWK -v endwk=$ENDWK '{
if($1>=startwk && $1<=endwk}print$1
}' weekfile > newfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Using the following code

STARTWK=042006
ENDWK=042007

nawk -F"|" -v startwk=$STARTWK -v endwk=$ENDWK '{
if ($1 >= startwk && $1 <= endwk)
print $1
}' weekfile

I get:
042007
042006

?:(

Madasafish



 
Again, sorry (I'd use yyyyww format ...).
What about this ?
Code:
STARTWK=042006
ENDWK=042007
nawk -F'|' -v startwk=$STARTWK -v endwk=$ENDWK '
function wy2yw(wy){return substr(wy,3)""substr(wy,1,2)}
BEGIN{s=wy2yw(startwk);e=wy2yw(endwk)}
{ if(wy2yw($1)>=s && wy2yw($1)<=e}print$1
}' weekfile > newfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top