For Programmers: Free Programming Magazines  


Home > Archive > AWK > June 2004 > read a record and use the value in subsequent search of another file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author read a record and use the value in subsequent search of another file
mehedi

2004-06-08, 8:55 pm

What i'm trying to do with awk
1. read a record from the file A
2. use the value retrieved from the file A in a search of file B

Below are two statements i need to combine but don't now how.
awk '{while ((getline tmp) > 0) print tmp;print NR;}' FILEA

awk '/Value from file A/ , /END/' FILEB
-------------

Thanks

Mehedi
Doug McClure

2004-06-09, 3:55 am

I have done something like this:

FNR == 1 {
# First line of this file
FileNumber++
}

FileNumber == 1 {
# Compute value from A
Value_from_A = ...
}

FileNumber == 2 {
# Search file B
if (match($0, Value_from_A))
{
# Do something
}
}

match() is intended to use a string as its first argument and a
regular expression as its second, but I believe the Value_from_A
string will be converted to a regular expression.

This might be a problem if Value_from_A contains any escape
characters. If it's just plain ASCII, you should be OK as is.

DKM

On 8 Jun 2004 13:09:10 -0700, mehedi.hashir@ibx.com (mehedi) wrote:

>What i'm trying to do with awk
>1. read a record from the file A
>2. use the value retrieved from the file A in a search of file B
>
>Below are two statements i need to combine but don't now how.
>awk '{while ((getline tmp) > 0) print tmp;print NR;}' FILEA
>
>awk '/Value from file A/ , /END/' FILEB
> -------------
>
>Thanks
>
>Mehedi



To contact me directly, send EMAIL to (single letters all)
DEE_KAY_EMM AT EarthLink.net. [For example X_X_X@EarthLink.net.]
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com