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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reverse search a text file from a specified line PacificWonder Shell Programming and Scripting 14 08-28-2008 04:28 PM
Log Search Script fuzion.hyd Shell Programming and Scripting 3 08-05-2008 03:48 PM
Small Search script appu1987 Shell Programming and Scripting 2 06-03-2008 10:14 PM
Help with search script bsandeep_80 UNIX for Advanced & Expert Users 9 09-06-2007 08:25 AM
Search script BCarlson Shell Programming and Scripting 14 02-05-2006 02:50 AM

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 10-09-2008
id4forum id4forum is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
reverse search in awk script

Hi,

I am new to awk. Actually I want to search a pattern A, when I get that line with pattern A then for one of the field of that line again I want search on that field (say pattern B)from start of the file.
I am using awk. Is nested searching possible in awk?

Please do the needful as soon as possible.

Thanks,
  #2 (permalink)  
Old 10-09-2008
a2156z a2156z is offline
Users Awaiting Email Confirmation
  
 

Join Date: Oct 2008
Posts: 30
I am unsure what do you need the output, line number ? if that, just use grep is ok.
grep -n "$A" "$file_name" | grep "$B" | awk '{print $1}'
Or the filed is specified? if that,
awk '$0~/A/ && $i == B{print NR}' "$file_name"

Last edited by a2156z; 10-09-2008 at 07:32 AM..
  #3 (permalink)  
Old 10-10-2008
id4forum id4forum is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Let me clear my doubt....I am searching for pattern A, once I get that pattern in file I get that entire line and extract its $i field(pattern B) in one variable(its known in advance) and again start search for pattern B from start of the file. I am using awk.

Thanks,
  #4 (permalink)  
Old 10-13-2008
id4forum id4forum is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Let me clear my doubt....I am searching for pattern A, once I get that pattern in file I take that entire line and extract its $i field(pattern B) in one variable(its not known in advance) and again start search for pattern B from start of the file. I am using awk.

Please suggest something in awk

Thanks,
  #5 (permalink)  
Old 10-13-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,047
search patternA first, when matched, put the $2(assume it contains patternB) in the variable pat, then go through the whole file content and print out all the lines contain patternB

Code:
awk '{
if(index($0,"patternA")!=0)
	pat=$2
arr[NR]=$0
}
END{
for(i in arr)
	if(index(arr[i],pat)!=0)
		print arr[i]
}' filename
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 09:46 PM.


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