I have 2 .txt files
INPUT FILE 1: contents of file 1(REQUEST DETAILS: RegRequest.txt):
2020-12-21 18:28:32,0000000001,[email protected],919876543210
2020-12-21 18:28:32,0000000002,[email protected],919876543211
2020-12-21 18:28:32,0000000003,[email protected],919876543212
INPUT FILE 2: contents of file 2(RESPONSE DETAILS: RegReponse.txt):
0000000001
0000000003
Output file:
2020-12-21 18:28:32,0000000001,[email protected],919876543210,true
2020-12-21 18:28:32,0000000002,[email protected],919876543211,false
2020-12-21 18:28:32,0000000003,[email protected],919876543212,true
The content of the input file2 tells us that which all request are success, in the above case 0000000001 and 0000000003 are success, so I have to create a output file containing the request file data and new column gets added saying whether its success or failure.
like below:
2020-12-21 18:28:32,0000000001,[email protected],919876543210,true
.
I will be getting 1 single file these 2 files are generated by executing my script but I got stuck at this point.
Here is my script I wrote to generate 2 different files as per the requirement
#!/bin/bash
#fetching only one file
`cat mainfile.cdr | grep -v Orig |awk '
BEGIN{ FS="|"; OFS="," }
{
split($4,RegReqArr,":");
if (RegReqArr[4] == 10) {
split($1,dateTime,",");
split($2,ReqidArr,":");
gsub(/^[^<]*|;.*/,"",$8)
split($17,MsisdnArr,":");
print dateTime[1],ReqidArr[2],substr($8,2,length($8)-2),MsisdnArr[2] } }' > RegRequest.txt`
`cat mainfile.cdr | grep -v Orig |awk '
BEGIN{ FS="|"; OFS="," }
{
split($4,RegReqArr,":");
if (RegReqArr[4] == 11) {
split($2,ReqidArr,":");
split($7,Response,":");
if (Response[2]==200) {
print ReqidArr[2]
} } }' > RegResponse.txt`
After generating these 2 files RegRequest.txt and RegReponse.txt I want to generate final file like below
2020-12-21 18:28:32,0000000001,[email protected],919876543210,true
2020-12-21 18:28:32,0000000002,[email protected],919876543211,false
2020-12-21 18:28:32,0000000003,[email protected],919876543212,true
question from:
https://stackoverflow.com/questions/65558259/generating-a-output-file-by-comparing-the-2-files-in-shell-script