![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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, |
|
||||
|
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.. |
|
||||
|
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, |
|
||||
|
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, |
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|