awk -F'[,:]' ' # separate by a coma or a colon
BEGIN{
print "COUNT,BNG_IP,PORT,OVLAN,DSLAM_IP" # start by displaying the header
}
{
gsub(" ", "") # remove any spaces to sanitize the input
}
FNR==NR { # apply the following block rule to the first file
I[$2,$3,$4]=$0 # make the fields 2,3,4 as an id for the array I and save the whole line in it
next # stop processing any more blocks and go to read the next record
}
I[$1,$3,$4]{ # if it gets here, it is processing the second file. Check there's something in for the key of fields
print I[$1,$3,$4], $2 # if an ID matches, display the whole record from file 1 + the added DSLAM_IP from file 2
}' OFS=',' surender_reddy.file1 surender_reddy.file2 # OFS (Output Field Separator) is set to be a coma
---------- Post updated at 05:30 PM ---------- Previous update was at 05:03 PM ----------
Quote:
Originally Posted by surender reddy
Thanks .Its working .Can you pls explain the command in detail.
Code:
awk -F, ' # use a coma as input separator
{gsub (/ /,_)} # substitute any white space for an underscore to balance the input
NR==FNR {split ($NF, T, ":") # for the first file, split the last field by colon and save it into an array T
DSLAM[$1,$3,T[1]]=$2 # create an array named DSLAM with the id made up from $1,$3,T[1] to save $2
next # move to the next record and skip the rest if this is file2
}
FNR==1 {print $0 FS "DSLAM_IP" # only for the first line of the second file,since the first file has been processed already. Print header.
next # skip the rest if it is the record is the first line of the second file at stdin
}
($2,$3,$4) in DSLAM {print $0 FS DSLAM[$2,$3,$4]} # if there a key named $2,$3,$5 in the previous made array DSLAM, display current line + coma + content stored in DSLAM[key].
' file2 file1
There is a text file that contains the data in the following format:
COLUMN1 COLUMN2
ABC 1
ABC 2
ABC 3
DEF 4
DEF 5
XYZ 7
We have to create a second text file... (4 Replies)
Hi,
how to read the 2 files and compare each other in shell script? i have 2 files test1 and test2, both files contains 20 character records.we have to compare file 1 records with file2, if exists then reject the record else we have to append it to test2 file. in file test1 around 100 single... (2 Replies)
hi experts
please help me to compare two files which are in different directory
file1<file will be master file>
(/home/rev/mas.txt}
ex x1
x2
file2 <will be in different folder>
(/home/rev/per/.....)
ex x3
x4
the filesinside per folder i need to compare with master file and the files... (2 Replies)
Hi All,
I am writing a shell script to print all the files in a particular folder.
This script is on solaris server .
I am using the lp command to send the requests .
lp -d printername filename .
The output I get is the request id.
Is there any way I can use the request Id to determine if... (1 Reply)
Hi,
Below is my issue which I desperately need and I want a shell script which can do this job.
I need this script as I m planning to put this for a system health check. Please assist me.
1. There are 10 log files in a particular location.
2. open each log file. Goto to the end of the... (4 Replies)
Hi Experts,
I have 2 files 1 file consists of 800 records and 2 file consists of 100 records with matching column as Membership_Num.So i need a script which will compare the 2 files and displays the output.As these are the files the script should take any delimter like (tab,comma) as input... (6 Replies)
Hi,
I have 2 files as below
FILE1.dat
co1|co2|co3
abnd|45.56|AZ
dkny|30.2|PA
sam|.23|VA
FILE.CTL
FILENAME|FILE1.dat
NO OF RECORDS|3
CHECKSUM|75.99
Could you please help me to write a shell script to compare
1. TOTAL RECORDS from FILE1.dat with NO of RECORDS in FILE.CTL
2.... (8 Replies)
Hi All,
I have 2 files like below
vi f1
frog
elephant
rabit
zebra
dog
vi f2
rabit
dog
==============
Now i want to comapre two files and the result will be
frog (8 Replies)