Range 
Author Message
 Range

************************************************************************
The following awk script will search for a specific IQ score of 100, &
then it will go two lines down, and report the file name that had that score.

  awk 'BEGIN {n=3;}{{if(index($0,"IQ score is 100")>0)n=0;else n++}
  {if(n==2){print $1}}}' $INPUT_FILE > $OUTPUT_FILE

My question is:
Q: How can I add a regular expression to this awk script so that it will
   report not just the files with a score of 100, but, all files within
   the range of 80 to 99?
************************************************************************
I tried using ~ /regular-expression/, but, that failed me:

Here's my best pass (which fails):

  awk 'BEGIN {n=3;}
  {{if(index($0,~ /IQ score is 8[0-9]|IQ score is 9[0-9]/)>0)n=0;else n++}
  {if(n==2){print $1}}}' $INPUT_FILE > $OUTPUT_FILE

My question is:
Q: How can I report all the files with an IQ score between a given range
   of 80 to 99?
------------------------------------------------------------
In this real-world problem, the $INPUT_FILE looks something like this:

   ...stuff...
   INFO (IQ): IQ score is 0 (best is 100).
   INFO (IQ): Program SKILL Lint finished with status FAIL.
        /tmp/ssk/testdir/file1.txt
   ...stuff...
   INFO (IQ): IQ score is 43 (best is 100).
   INFO (IQ): Program SKILL Lint finished with status FAIL.
        /tmp/ssk/testdir/file2.txt
   ...stuff...
   INFO (IQ): IQ score is 87 (best is 100).
   INFO (IQ): Program SKILL Lint finished with status PASS.
        /tmp/ssk/testdir/file3.txt
   ...stuff...
   INFO (IQ): IQ score is 100 (best is 100).
   INFO (IQ): Program SKILL Lint finished with status PASS.
        /tmp/ssk/testdir/file4.txt
   ...
   etc.
------------------------------------------------------------
Q: How can I add a regular expression to this awk script to
   report all the files with an IQ score ranging betwen 80 and 99?
   (The file name is always two lines below the score itself.)
------------------------------------------------------------

John Gianni



Mon, 16 Apr 2001 03:00:00 GMT  
 Range

Quote:

>************************************************************************
>The following awk script will search for a specific IQ score of 100, &
>then it will go two lines down, and report the file name that had that score.

>  awk 'BEGIN {n=3;}{{if(index($0,"IQ score is 100")>0)n=0;else n++}
>  {if(n==2){print $1}}}' $INPUT_FILE > $OUTPUT_FILE

>My question is:
>Q: How can I add a regular expression to this awk script so that it will
>   report not just the files with a score of 100, but, all files within
>   the range of 80 to 99?
>************************************************************************
>I tried using ~ /regular-expression/, but, that failed me:

>Here's my best pass (which fails):

>  awk 'BEGIN {n=3;}
>  {{if(index($0,~ /IQ score is 8[0-9]|IQ score is 9[0-9]/)>0)n=0;else n++}
>  {if(n==2){print $1}}}' $INPUT_FILE > $OUTPUT_FILE

>My question is:
>Q: How can I report all the files with an IQ score between a given range
>   of 80 to 99?
>------------------------------------------------------------
>In this real-world problem, the $INPUT_FILE looks something like this:

>   ...stuff...
>   INFO (IQ): IQ score is 0 (best is 100).
>   INFO (IQ): Program SKILL Lint finished with status FAIL.
>    /tmp/ssk/testdir/file1.txt
>   ...stuff...
>   INFO (IQ): IQ score is 43 (best is 100).
>   INFO (IQ): Program SKILL Lint finished with status FAIL.
>    /tmp/ssk/testdir/file2.txt
>   ...stuff...
>   INFO (IQ): IQ score is 87 (best is 100).
>   INFO (IQ): Program SKILL Lint finished with status PASS.
>    /tmp/ssk/testdir/file3.txt
>   ...stuff...
>   INFO (IQ): IQ score is 100 (best is 100).
>   INFO (IQ): Program SKILL Lint finished with status PASS.
>    /tmp/ssk/testdir/file4.txt
>   ...
>   etc.
>------------------------------------------------------------
>Q: How can I add a regular expression to this awk script to
>   report all the files with an IQ score ranging betwen 80 and 99?
>   (The file name is always two lines below the score itself.)
>------------------------------------------------------------

Rather than mess with all that regular expression stuff, it's
easier (IMO) to do it this way (untested):

awk '/IQ score is / && $6 >= 80 && $6 <= 99 {printline = NR +2}
     NR == printline {print)' infile

That ought to do the job, for the file format you show.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Mon, 16 Apr 2001 03:00:00 GMT  
 Range
  ***********************************************************************
The following awk script will search for a specific IQ score of 100, &
then it will go two lines down, and report the file name that had that score.

  awk 'BEGIN {n=3;}{{if(index($0,"IQ score is 100")>0)n=0;else n++}
  {if(n==2){print $1}}}' $INPUT_FILE > $OUTPUT_FILE

My question is:
Q: How can I add a regular expression to this awk script so that it will
   report not just the files with a score of 100, but, all files within
   the range of 80 to 99?
************************************************************************
I tried using ~ /regular-expression/, but, that failed me:

Here's my best pass (which fails):

  awk 'BEGIN {n=3;}
  {{if(index($0,~ /IQ score is 8[0-9]|IQ score is 9[0-9]/)>0)n=0;else n++}
  {if(n==2){print $1}}}' $INPUT_FILE > $OUTPUT_FILE

My question is:
Q: How can I report all the files with an IQ score between a given range
   of 80 to 99?
------------------------------------------------------------
In this real-world problem, the $INPUT_FILE looks something like this:

   ...stuff...
   INFO (IQ): IQ score is 0 (best is 100).
   INFO (IQ): Program SKILL Lint finished with status FAIL.
        /tmp/ssk/testdir/file1.txt
   ...stuff...
   INFO (IQ): IQ score is 43 (best is 100).
   INFO (IQ): Program SKILL Lint finished with status FAIL.
        /tmp/ssk/testdir/file2.txt
   ...stuff...
   INFO (IQ): IQ score is 87 (best is 100).
   INFO (IQ): Program SKILL Lint finished with status PASS.
        /tmp/ssk/testdir/file3.txt
   ...stuff...
   INFO (IQ): IQ score is 100 (best is 100).
   INFO (IQ): Program SKILL Lint finished with status PASS.
        /tmp/ssk/testdir/file4.txt
   ...
   etc.
------------------------------------------------------------
Q: How can I add a regular expression to this awk script to
   report all the files with an IQ score ranging betwen 80 and 99?
   (The file name is always two lines below the score itself.)
------------------------------------------------------------

John Gianni
===================================================================
Some general comments:
awk was made not to write too many ifs
=============================

awk '/^INFO (IQ): IQ score is [89][0-9] (best is 100).$/ {goodLineNR=NR }
(NR>2)&&(NR-goodLineNR==2) {print $1 }' $INPUT_FILE > $OUTPUT_FILE

alternative for other numerical conditions:
awk '($0~/IQ score is/)&&($6>79)&&($6<100) {goodLineNR=NR }
(NR>2)&&(NR-goodLineNR==2) {print $1 }' $INPUT_FILE > $OUTPUT_FILE

not tested
 LMS
free sed/awk book:
      ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/1997/97-2-007.ps.gz
      ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/1997/97-2-007.tar.gz



Mon, 16 Apr 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CW4 - Ranges question - changing range values while running

2. Range limits type : Range of values

3. Range#size, Range#length

4. * y for y in range(3) ] * x for x in range(2) ]

5. Locator on Browse with Range limit : 'RANGE OF VALUES'

6. exponential range

7. coding a data range (second post attempt)

8. coding a date range

9. Slider range

10. Excel activex, setting multiple cells in a column range

11. DB Date Range Field Type

12. using and active using range

 

 
Powered by phpBB® Forum Software