The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Building Full-Text Search Applications with Oracle Text iBot Oracle Updates (RSS) 0 04-06-2008 05:10 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Simplistic Questions (Basically I am dumb.) fatalrealm UNIX for Dummies Questions & Answers 1 10-16-2007 10:58 PM
Super dumb questions by a newbie johnjm22 UNIX for Dummies Questions & Answers 8 04-13-2004 10:35 AM
Two dumb questions Darkstripes UNIX for Dummies Questions & Answers 1 07-15-2003 10:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2008
J.T. J.T. is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 3
The dumbest of dumb Text Search questions

I've done some due diligence by searching the forum for an answer, but to no avail. Excuse this most elementary of questions.

Using grep I can search a file and derive the line number of the text I'm searching for. Now for the elementary part, how do I continue a search for a different search criteria from that line to the end of the file?

Thanks in advance.
  #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
  #3 (permalink)  
Old 11-20-2008
J.T. J.T. is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 3
The dumbest of dumb Text Search questions

Thanks Joey for your response.

One additional question if you would, how would I then assign the value from the awk statement to a variable for later use in my script ?
  #4 (permalink)  
Old 11-20-2008
J.T. J.T. is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 3
The dumbest of dumb Text Search questions

I was able to assign the results of the awk statement to a variable, but it looks like the supplied code only returns a result if the 2nd search criteria (blah) is in the 1st column. If the 2nd search criteria is not in the 1st column as follows, nothing is returned:

Code:
 
blah
blah
ABC
123
456
789
DEF
yech
yech
GHI blah
JKL blah
How do I modify this logic to search beyond the 1st coumn?
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 11:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0