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!

Finding what number of record containing x

Status
Not open for further replies.
Oct 22, 2001
215
US
I got a data file that contains an "x". I need to know what number that is nth record number that got this "x"
what would be the easiest way to do this? I also need to know, if I want to see the "n"th row how to display this? TIA
 
try this (untested)
awk '{ $0 ~ /x/ printf("line number %d - Contents %s",NR,$0)}' your_data_file

HTH ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Ooops - too much of a hurry !
You need an if()
awk '{ if ($0 ~ /x/) printf("line number %d - Contents %s",NR,$0)}' your_data_file

This will, of course, show ALL rows containing 'x'
HTH ;-)


Dickie Bird
db@dickiebird.freeserve.co.uk
 
how 'bout:

awk '/x/ { printf("line number %d - Contents %s",NR,$0)}' your_data_file vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Rats - Vlad is still cheaper ! ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top