File comparison of different format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File comparison of different format
# 1  
Old 02-13-2012
Question File comparison of different format

i have file as
FileD
Code:
funny       mou1
funny       mou2
raspe       mou4
damn       mou1

this file is a csv with /t.
i want to find all values with the first column of this file in fileB and then check for in that line if the second column vvalues are present or not .

for eg suppose in fileB there is a line
Code:
funnymou1:20112
funnymou2:34470
raspmou3:nhdhv
raspmou4:38748

fileD has 1st content of 1st column is "funny"
so funny would be checked in fileB if found then "funny" second column will be checked i.e mou1 will be checked in that line if present than ok. if not present than it will be written in other fileE.if first column of fileD is present than only second column of fileD is checked in that line .if first column field can be present in more than one rows in fileB all lines of fileB should be then compared with second column of fileD if found then not written ... if not found then written in fileE
so for
raspe mou4 --- as raspe is not present in fileB it will be written in fileE as output

so
funny mou1
is present so it will not be written in fileE
next
funny mou2 is also present in fileB so not writen in fileE
now
raspe mou4
damn mou1 will be wriiten in fileE as it is not present in fileB.

o/p of fileE
Code:
raspe    mou4
damn    mou1

can it be done using awk ... large database is present!!
# 2  
Old 02-13-2012
You can try something like:
Code:
awk 'NR==FNR{a[$1$2]=$0;next}$1 in a{delete a[$1]}END{for(i in a){print a[i]}}' fileD FS=: fileB > fileE

# 3  
Old 02-13-2012
Hi franklin52,

its only working for this eg. but not for my database of 80000
As you have used here ":" as feild seperator. but column 2 of fileD can be present anywhere before or after of any symbols . i will like to give my files as

fileB :
Code:
 

02.09.2011:MOU04/KUBIS--R_Lieferung_1/KUBIS_V15.0/vpn_wls_15-0-0b01
02.09.2011:MOU04/KUBIS--R_Lieferung_2/KUBIS_V15.0/apng_wls_15-0-0b02
31  02.09.2011:MOU04/KUBIS--R_Lieferung_2/KUBIS_V15.0/ecc_wls_15-0-0b02
32  02.11.2010:PPMOU/VOMS--VOMS-ASR3244/VoMS2.3.0_LieferungZu_AO-Order004385
33  02.11.2010:PPMOU/PRMKONF-RBO-01.00.13.00/XXX_mandatory_LieferungZu_AO-Order004513
33  02.11.2010:PROD/PRMKONF-RBO-01.00.13.00/XXX_mandatory_LieferungZu_AO-Order004513
34  02.11.2011:WOMS2/KUBIS--S_Lieferung_1/KUBIS_V16.0/kubis_db_16-0-0b01
02.11.2011:WOMS2/KUBIS--S_Lieferung_2/KUBIS_V16.0/kubis_db_16-0-0b02
36  02.11.2011:WOMS2/KUBIS--TS-InTime-VV/Lieferung_WoM_Maxx_VV_01_20111026
37  02.11.2011:WOMS2/PA--PA-MaxX-Konf/PA-MaxX-Konf-01.00.00.00
38  02.11.2011:WOMS2/PM--PM-5.0/PRM-LIB-05.00.00.00
39  02.11.2011:WOMS2/PM--PM-MaxX-Konf/PRMKONF-MaxX-01.00.00.00
40  02.11.2011:WOMS2/SALES--SK-Tools-2.0.0_Lieferung_01_20111024/SK-Tools-2.0/database-dist_2-0-0b01
41  02.11.2011:WOMS2/SALES--SK-Tools-2.0.0_Lieferung_01_20111024/SK-Tools-2.0/salescomponent-dist_2-0-0b01
42  02.12.2010:PPMOU/VOMS--AO-intern_RU10_VOMS_ASR3605/XXX_mandatory_LieferungZu_AO-Order004638

this is not a csv file or it does not contain any seperator. its just a file.

and my fileD is as follows
Code:
PRMKONF-RBO-01.00.13.00          PROD
REL_001.630.008_LieferungZu_AO-Order004266      PROD
CASS-CR099-1-2T         PPMOU
CASS-CR099-1-2T         PROD

this is a csv file . so now i want to compare this file first value of fileD ie "PRMKONF-RBO-01.00.13.00" in fileB. now if it is found in fileB whole line is copied and checked for second column of "PRMKONF-RBO-01.00.13.00" if this second column is present in that line or not. ie second column is PROD . so if this PROD is present in that line than it is not redirrected for output. if this is not present in that file then that row from fileD is redirected for output.

so output shall be
Code:
REL_001.630.008_LieferungZu_AO-Order004266      PROD
CASS-CR099-1-2T         PPMOU
CASS-CR099-1-2T         PROD

this PRMKONF-RBO-01.00.13.00 PROD is not outputed as "PRMKONF-RBO-01.00.13.00" is present and that line contains "PROD".
and also PRMKONF-RBO-01.00.13.00 can be present in many lines of fileB and each line should be considered for checking second columns of fileD.as for above example
"PRMKONF-RBO-01.00.13.00" was present in two line as

33 02.11.2010:PPMOU/PRMKONF-RBO-01.00.13.00/XXX_mandatory_LieferungZu_AO-Order004513
33 02.11.2010:PROD/PRMKONF-RBO-01.00.13.00/XXX_mandatory_LieferungZu_AO-Order004513

so PROD will be found in any of this line.

many thanks in advance..
# 4  
Old 02-15-2012
Try this:
Code:
awk '{print $2 "/" $1}' fileD > tempfile
grep -v -f tempfile fileB > fileE
rm tempfile

# 5  
Old 02-15-2012
not working Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help to format one txt file to required format

Hello Everyone, I have one source file which is genarated by SAP in different format(Which I've never seen). I need to convert that file to required format and I need to read this target file from Datastage to use this in my Jobs. So I do not have any other options except to use Unix script to... (4 Replies)
Discussion started by: Prathyu
4 Replies

2. Shell Programming and Scripting

File Comparison: Print Lines not present in another file

Hi, I have fileA.txt like this. B01B02 D0011718 B01B03 D0012540 B01B04 D0006145 B01B05 D0004815 B01B06 D0012069 B01B07 D0004064 B01B08 D0011988 B01B09 D0012071 B01B10 D0005596 B01B11 D0011351 B01B12 D0004814 B01C01 D0011804 I want to compare this against another file (fileB.txt)... (3 Replies)
Discussion started by: genehunter
3 Replies

3. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

4. Shell Programming and Scripting

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (2 Replies)
Discussion started by: Samtel
2 Replies

5. UNIX for Dummies Questions & Answers

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (1 Reply)
Discussion started by: Samtel
1 Replies

6. Shell Programming and Scripting

File Comparison

Hi i have 2 csv files a.csv and b.csv with the same number of columns and a list of values in both of it. Each and every individual value in both the files need to compared and if it matches then print correct in a new csv file otherwise print Incorrect eg a.csv 1,12/27/2007,Reward,$10.00... (5 Replies)
Discussion started by: naveenn08
5 Replies

7. Shell Programming and Scripting

Output format - comparison with I/p file

Hi, I have a file which contains more than 1 lakh records like following: a. name, id, city, state, country, phone (Expected I/P file format) name, id, city,, state, country, phone (Current I/P file format ) I want to achieve following tasks, a, Remove the extra comma in the... (1 Reply)
Discussion started by: velappangs
1 Replies

8. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

9. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

10. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies
Login or Register to Ask a Question