Hi All,
The problem that I am experiencing is when the pattern is not found in file2,
print a mesg "0133333333 No Info Available". I have tried different ways but cannot
seem to find a solution.
My Code
awk 'BEGIN{printf "%10s %25s %20s %15s\n","A_NUM","DATE/TIME", "B_NUM","DURATION"}
FNR==NR {
t[$1]=$1; next
}
{if(t[$1]==$1){
if($4=="0" && ($4!="[A-Z,a-z] || $4!=\"---")){
DUR=$4
}
else
{
DUR=substr($4,1,(length($4)-1))
}
print "%10s %20s %5s %20s %10s\n",$1, substr($2,1,10), substr($2,11,18), $3, (DUR)
}
}' file1 file2
file1
======
0111111111 2006/07/01
0122222222 2006/07/01
0133333333 2006/07/01
file2
=====
A_NUM disconnect_date_time B_NUM C_DUR
---------------- ---------------------------------------------- ------------------------ -----------
0111111111 2006/07/0310:01:21 0800000000 0
0111111111 2006/07/0310:12:50 0800000000 4930
(2 rows affected)
0122222222 2006/07/0911:20:53 66666666 1210
0122222222 2006/07/0922:03:42 0333333333 5890
(2 rows affected)
A_NUM disconnect_date_time B_NUM C_DUR
---------------- ---------------------------------------------- ------------------------ -----------
(0 rows affected)
expected results
==============
A_NUM DATE/TIME B_NUM DURATION
0111111111 2006/07/03 10:01:21 0800000000 0
0111111111 2006/07/03 10:12:50 0800000000 493
0122222222 2006/07/09 11:20:53 66666666 121
0122222222 2006/07/09 22:03:42 0333333333 589
0133333333 No Info Available
Many Thanks
Chris
The problem that I am experiencing is when the pattern is not found in file2,
print a mesg "0133333333 No Info Available". I have tried different ways but cannot
seem to find a solution.
My Code
awk 'BEGIN{printf "%10s %25s %20s %15s\n","A_NUM","DATE/TIME", "B_NUM","DURATION"}
FNR==NR {
t[$1]=$1; next
}
{if(t[$1]==$1){
if($4=="0" && ($4!="[A-Z,a-z] || $4!=\"---")){
DUR=$4
}
else
{
DUR=substr($4,1,(length($4)-1))
}
print "%10s %20s %5s %20s %10s\n",$1, substr($2,1,10), substr($2,11,18), $3, (DUR)
}
}' file1 file2
file1
======
0111111111 2006/07/01
0122222222 2006/07/01
0133333333 2006/07/01
file2
=====
A_NUM disconnect_date_time B_NUM C_DUR
---------------- ---------------------------------------------- ------------------------ -----------
0111111111 2006/07/0310:01:21 0800000000 0
0111111111 2006/07/0310:12:50 0800000000 4930
(2 rows affected)
0122222222 2006/07/0911:20:53 66666666 1210
0122222222 2006/07/0922:03:42 0333333333 5890
(2 rows affected)
A_NUM disconnect_date_time B_NUM C_DUR
---------------- ---------------------------------------------- ------------------------ -----------
(0 rows affected)
expected results
==============
A_NUM DATE/TIME B_NUM DURATION
0111111111 2006/07/03 10:01:21 0800000000 0
0111111111 2006/07/03 10:12:50 0800000000 493
0122222222 2006/07/09 11:20:53 66666666 121
0122222222 2006/07/09 22:03:42 0333333333 589
0133333333 No Info Available
Many Thanks
Chris