help with generate a new text

textfile 1

BRM501,LOGON,BX12_28,2012 SEP 20 15:01:58
BRM502,LOGOFF,BX12_34,2012 SEP 20 14:56:06
BTT396,LOGON,BT03_8,2012 SEP 20 15:03:08

textfile 2

BRM501,DEPLOYED
BRM502,DEPLOYED

to combine 2 textfile result together and create new file
result

BRM501,LOGON,BX12_28,2012 SEP 20 15:01:58,DEPLOYED
BRM502,LOGOFF,BX12_34,2012 SEP 20 14:56:06,DEPLOYED
BTT396,LOGON,BT03_8,2012 SEP 20 15:03:08, UNDEPLOYED

KShell
Hi guys I need a format or an approach to this problem i am facing to combine 2 log and generate a new result.. help is very much appreciated..
i have 100 of records in textfile 1 and 77 records in textfile 2. So I pretty much need to start with loops =(

awk -F, 'FNR==NR{a[$1]=$2;next}{$(NF+1)=($1 in a)?a[$1]:"UNDEPLOYED"}1' OFS=, file2 file1

Is this what you what?

1 Like
#remove header and footer
sed '1,16 d' </tmp/$resultEqpt_dir >/tmp/$resultEqpt_dir.out
sed '111,116 d' </tmp/$resultEqpt_dir.out >/tmp/$resultEqpt.log
#Housekeeping: Delete the result temp file
rm /tmp/$resultEqpt_dir.out
rm /tmp/$resultEqpt_dir
#Execute the second SQL query
$cur_dir/select-eqptDeployment-bt-status > /tmp/$resultEqptstatus_dir
#remove header and footer
sed '1,16 d' </tmp/$resultEqptstatus_dir >/tmp/$resultEqptstatus_dir.out
sed '88,93 d' </tmp/$resultEqptstatus_dir.out >/tmp/$resultEqptstatus.log

#Housekeeping: Delete the result temp file
rm /tmp/$resultEqptstatus_dir.out
rm /tmp/$resultEqptstatus_dir
awk -F, 'FNR==NR{a[$1]=$2;next}{$(NF+1)=($1 in a)?a[$1]:"UNDEPLOYED"}1' OFS, /tmp/$resultEqpt.log /tmp/$resultEqptstatus.log

I gt my error:

awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1

is it cos i had perform sed earlier?

Use nawk or /usr/xpg4/bin/awk instead of awk .

nope still cant work :frowning:

---------- Post updated 09-21-12 at 10:51 AM ---------- Previous update was 09-20-12 at 06:22 PM ----------

i m looking for the solution that is if txtfile 1 have the record file found in txtfile 2.
new > result file will have txtfile1 with line + 'DEPLOYED'
else if record file is not found in txtfile 2 +'UNDEPLOYED'

---------- Post updated at 11:32 AM ---------- Previous update was at 10:51 AM ----------

solution found... thanks elixir_sinari