searching blocks of lines in a file ... 
Author Message
 searching blocks of lines in a file ...

Hi, I have a text file (infile) that consists of sets of 10 lines
separated by an empty line. I would like to search the entire file and
output those sets of 10 lines which match a criteria onto another file
(outfile).  The criteria being the 3rd line of each set that whose
first filed = desires_value qualifies that set for output; else the
read lines are ignored and the next set of 10 lines are examined, till
the end of the file. How could this be done in awk. I appreciate your
help.

Martin

here is how it is:

/* start of set 1 */
line 1 fieldid: some value
line 2 fieldid: some value
line 3 fieldid: some value  /* if value == desired value output all 10
lines for the set. else skip them, and go to next set. */
...
line 10

/start of set 2 */
....

all the way to the end of the file.



Fri, 11 Nov 2005 06:36:47 GMT  
 searching blocks of lines in a file ...

% Hi, I have a text file (infile) that consists of sets of 10 lines
% separated by an empty line. I would like to search the entire file and
% output those sets of 10 lines which match a criteria onto another file
% (outfile).

Set RS to "" and FS to "\n". Test against whatever field is of interest

 BEGIN { RS = ""; FS = "\n" }
 $3 == whatever { print }
--

Patrick TJ McPhee
East York  Canada



Fri, 11 Nov 2005 08:14:33 GMT  
 searching blocks of lines in a file ...
Thanks for the reply; but I need to print all the 10 lines, if the
first filed on the third line matches the desired value. And this
needs to be done for the entire file, for all the sets of 10 lines
that match this criteria. Does this solution do it?
or is something missing?
Martin


Quote:


> % Hi, I have a text file (infile) that consists of sets of 10 lines
> % separated by an empty line. I would like to search the entire file and
> % output those sets of 10 lines which match a criteria onto another file
> % (outfile).

> Set RS to "" and FS to "\n". Test against whatever field is of interest

>  BEGIN { RS = ""; FS = "\n" }
>  $3 == whatever { print }



Fri, 11 Nov 2005 19:15:03 GMT  
 searching blocks of lines in a file ...

Quote:

>Thanks for the reply; but I need to print all the 10 lines, if the
>first filed on the third line matches the desired value. And this
>needs to be done for the entire file, for all the sets of 10 lines
>that match this criteria. Does this solution do it?
>or is something missing?

Hint:  

Try it!

Chuck Demas

Quote:




>> % Hi, I have a text file (infile) that consists of sets of 10 lines
>> % separated by an empty line. I would like to search the entire file and
>> % output those sets of 10 lines which match a criteria onto another file
>> % (outfile).

>> Set RS to "" and FS to "\n". Test against whatever field is of interest

>>  BEGIN { RS = ""; FS = "\n" }
>>  $3 == whatever { print }

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

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



Fri, 11 Nov 2005 19:50:14 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Search file and print line + next line?

2. Search and replace text in a file based on a specific line

3. std blocks vs blocks+cache ( was: block behavior)

4. search and print a block

5. reversing lines char by char, but not the line order in a file

6. how to read text files line by line?

7. reading file line by line

8. new question in how can i read data from file line by line

9. How to compare two files line-by-line

10. line-by-line file read

11. Read a text file line by line

12. searching one file using the contents of another file

 

 
Powered by phpBB® Forum Software