search and combine lines in awk

Hi All,

I have 1 "keyword" file like this:

00-1F-FB-00-04-18
00-19-CB-8E-66-DF
00-1F-FB-00-48-9C
00-1F-FB-00-AA-4F
....

and the 2nd "details" file like this:

Wed Feb 11 00:00:02 2009
NAS-IP-Address = xxxxxxxxxxxxxxxxxx
Class = "P1-SHT-AAA01;1233704662;4886720"
Calling-Station-Id = "00-1F-FB-00-48-B5"
Acct-Status-Type = Stop
Acct-Session-Id = "0000000088730000"
Acct-Input-Octets = 276384
Acct-Output-Octets = 5445853
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Packets = 3036
Acct-Output-Packets = 4507
Acct-Session-Time = 6222
Acct-Terminate-Cause = NAS-Error
Framed-IP-Address = xxxxxxxxxxxxx
WiMAX-BS-ID = 000012A00452
User-Name = "xxxxxxxxxxxxxxxxx"
--
Wed Feb 11 00:00:17 2009
NAS-IP-Address = xxxxxxxxxxxxxxxxxx
Class = "P1-SHT-AAA01;1233704662;4886720"
Calling-Station-Id = "00-1F-FB-00-48-B6"
Acct-Status-Type = Stop
Acct-Session-Id = "0000000088730000"
Acct-Input-Octets = 276384
Acct-Output-Octets = 5445853
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Packets = 3036
Acct-Output-Packets = 4507
Acct-Session-Time = 6222
Acct-Terminate-Cause = NAS-Error
Framed-IP-Address = xxxxxxxxxxxxx
WiMAX-BS-ID = 000012A00452
User-Name = "xxxxxxxxxxxxxxxxx"
--
Wed Feb 11 00:00:17 2009
NAS-IP-Address = xxxxxxxxxxxxxxxxxx
Class = "P1-SHT-AAA01;1233704662;4886720"
Calling-Station-Id = "00-1F-FB-00-48-B7"
Acct-Status-Type = Stop
Acct-Session-Id = "0000000088730000"
Acct-Input-Octets = 276384
Acct-Output-Octets = 5445853
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Packets = 3036
Acct-Output-Packets = 4507
Acct-Session-Time = 6222
Acct-Terminate-Cause = NAS-Error
Framed-IP-Address = xxxxxxxxxxxxx
WiMAX-BS-ID = 000012A00452
User-Name = "xxxxxxxxxxxxxxxxx"
......

and I want to collect only the "calling-station-id" and the "username" field like below:

00-1F-FB-00-48-B5,xxxxxxxxxxxxxxxxx
00-1F-FB-00-48-B6,xxxxxxxxxxxxxxxxx
00-1F-FB-00-48-B7,xxxxxxxxxxxxxxxxx
.....

Really appreciate anyone help on this. thanks

In the example the 1st file with the list of (I assume) Calling-Station-Ids will not match with any in the 2nd example file. So this is just an unlucky example or does the 1st file not really have to correspondent with any match of Calling-Station-Ids in the 2nd file?

You mean in one file you will have the calling Calling-Station-Id and you want to prepare a list of Calling-Station-Id and user name for those Calling-Station-Id ???

hi zaxxon

the above file2 only for example and what Iam trying to do is pulling details for each keyword from file1 using file2.

ranjit,
yes, that what I want to do if I understood you correctly.
Thanks

grep -E "Calling-Station-Id|User-Name" second.file | tr "\n" "=" | grep -f first.file|cut -d"=" -f2-4

With one awk command:

awk -F"\"" '
NR==FNR{a[$0];next}
$2 in a{p=$2}
p && /User-Name =/{print p "," $2;p=""}
' file1 file2

Regards

hi ranjit, your script output just 1 line. Fraklin, your script working fine. let me analysis the output see if everyting fine. thanks all for the help