awk - find first instance of string after NR==10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - find first instance of string after NR==10
# 1  
Old 03-28-2011
awk - find first instance of string after NR==10

How do I use awk to find the NR of first instance of a specific string after eg NR==10?

I need to find the first instance of the word "class" after a specific NR.
# 2  
Old 03-28-2011
Code:
awk 'FNR>10 && /class/ {print FNR}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 03-28-2011
To bail out after the first occurrence of "class", modify vgersh99's {print FNR} to {print FNR; exit}.

Regards,
Alister
These 2 Users Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

win2008R2 using gnu grep/awk to find only the I instance out of the command

Ok, running tsm on 2008R2, and I have the gnu awk and grep installed...I want to only capture inactive (I) files inside of the backup...I can get this to work on linux, but because windows interprets " ' ` differently, i can't get it to print out right...Here's what I have: so basically... (8 Replies)
Discussion started by: nextreme
8 Replies

2. Shell Programming and Scripting

grep for a string until instance of a space

Hey guys, I'm having a bit of trouble getting this to work using either sed or grep. It's possible awk might be the ticket I need as well, but my regulat expression skills aren't quite up to the task for doing this. I'm looking to grep for the string ERROR from the following log up until any... (6 Replies)
Discussion started by: terrell
6 Replies

3. Shell Programming and Scripting

Complex find and replace only 1st instance string with dynamic combination

test.txt is the dynamic file but some of combination are fix like below are the lines ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off = disabled the test.txt can content them in any order #cat test.xt ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off =... (5 Replies)
Discussion started by: SilvesterJ
5 Replies

4. Shell Programming and Scripting

grep second instance of same string

Hi all, i am new to unix scripting in ksh or any shell for that matter. I have downloaded a xml file from a website and saved on my local harddrive. inside the xml, the same tag is listed multiple times. <title>Tonight</title> <title>Thursday</title> <title>Friday</title>... (6 Replies)
Discussion started by: scubasteve39
6 Replies

5. Shell Programming and Scripting

awk - last instance of a string

How do I use awk to find the last occurence of a string in a file? (3 Replies)
Discussion started by: locoroco
3 Replies

6. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

7. UNIX for Dummies Questions & Answers

replacing a particular instance in a string globally

Hi, I'm trying to update the last two characters coming in a string globally in a file. Here is the sample data: file1 In file1, I want to have all instances replace where _o is appearing in the end of a word with _g. If _o is appearing in the middle or any other position except the... (2 Replies)
Discussion started by: er_ashu
2 Replies

8. Shell Programming and Scripting

find the first instance after a string

I have this file (below) and need to get out specific data that appears after OSE1_1.FIX, but before OSE1_2.FIX. Specifically I need to get all of the data after "ROW80_20:", "ROW80_21:", "ROW80_22:" & "ROW80_23:" then I need to do the same for data the appears after OSE1_2.FIX, but before... (2 Replies)
Discussion started by: josslate
2 Replies

9. Shell Programming and Scripting

Search the last instance of a string in a file

I have a big database log file which keepsgrowing daily. OS is HP UX. Here is a small part of it: Tue Jan 27 04:03:22 2009 : add session begin for mfgeb on /dev/pts/th. : Converting relative path to absolute path. : add session end. Tue Jan 27 04:03:29... (6 Replies)
Discussion started by: dinesh1178
6 Replies

10. Shell Programming and Scripting

replace nth instance of string

Hi all, I have file with following content ........................... ..........TEST.......... ..........TEST.......... ..................... .....TEST.......... ..................... ..................... .....TEST.......... I want to replace nth "TEST" with "OK" using... (4 Replies)
Discussion started by: uttamhoode
4 Replies
Login or Register to Ask a Question