Selecting records from file on criteria.

Can I have 2 files as in input to the awk command?

Situation is somewhat below,

File A contains number & value delimited by a space.
File B contains number as a part of a line. I am not supposed
to retrieve more than 1 number from a line.

If number from file B matches with number from file A, then I will
retrieve value part from file A. I will store this found,
number - value pair in file C.

Would it be possible with single awk command? Or is there any suggestions to implement this?

Use paste file file2 | awk

paste creates one big line from the 'parallel' lines in the input
files

example:

file1:
dog
cat 
chicken

file2:
big
bigger


paste file1 file2
output:
dog big
cat bigger
chicken

I do some thing like this ...

>file3
exec < file2
while read line
do
grep "$line" file1 >> file3
done

sort -u file3

Bhargav

if I use exec my telnet window disappears.
None of your solutions suggested work for me.

I have to read file A, read a number
Read file B search for this number & extract description beyond it.

File A

xxxx1111yyyyy
aaaa2222bbbbb
cccc3333ddddd

File B
1111 desc1
2222 desc2

I know, awk deals with only 1 file.

Any suggestions?

It seems to me if you gave us all of the requirements up front you would get a better answer.

What is your exact output supposed to be? just the description?
Or the common number field followed by the description?

try

man join

for your edification.

Based on your requirements so far:

awk ' { print substr($0,4,4) } ' file1 | sort -u  tmp.sed
grep -f tmp.sed file2 | awk ' {  print $2 } '

This prints descriptions for each record in file1.

Jim
Thanks, Your solution helps.

Guys/Gals please suggest me good links where I can start with basics of shell scripts including awks.

Using awk ... u were originally looking for .....

awk -v s="file2" '{
while(getline a[x++] <s ) ;
for(x in a)
{
if($0 ~ substr(a[x++],5,4))
{
print $0 ;
}
}

}' file1

http://doc.novsu.ac.ru/oreilly/unix/

Complete books in html format for mastering sed & awk, shell scripting and more, enjoy.