The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 11-20-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Not all put together, but shows some pieces to investigate

Show the initial file.
Create a duplicate with line numbers.
Set variable mline equal to first occurence of ABC.
Echo variable $mline.
Use awk to find line number > 3 (value of ml) and the word blah.
Note that I did not find the earler blah entries.

[I believe with awk, a couple of those steps could be skipped by utilizing the record number parameter.]

Code:
> cat file73
blah
blah
ABC
123
456
789
DEF
yech
yech
blah
blah

> cat -n file73 >file73.n
> mline=$(grep -n ABC file73 | head -1 | cut -d":" -f1)
> echo $mline
3
> awk -v ml=$mline '$1>ml && $2=="blah" {print}' file73.n
    10  blah
    11  blah