compare three files and insert a blank line at each mismatch


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare three files and insert a blank line at each mismatch
# 1  
Old 06-18-2009
compare three files and insert a blank line at each mismatch

i need to compare three files in unix
a.txt b.txt c.txt
1 2 1
2 5 3
4 6 5
5 6
6

i need to insert a blank line in the file if i don't find a match
and put the items at the same column if found a match
The items in the files appear in sorted order

The output should be
a.txt b.txt c.txt
1 blank 1
2 2 blank
blank blank 3
4 blank blank
5 blank 5
6 6 6
# 2  
Old 06-18-2009
What have you tried, please share, so that someone can guide you.
# 3  
Old 06-18-2009
Rakesh i have three columns in a file where numbers come in sorted order

1 2 1
2 5 3
4 6 5
5 6
6


Now i want to compare first item, second item third item and so on in each column
if i get a match in all three i let all the items remain as it is

eg in above

6 6 6

if i don't get a match i let the minimum of this at the same place and shift the other(s) down.

eg in the first line

1 2 1

i need to get

1 blank 1
blank 2 blank

so the total output of the above input file should look like

1 blank 1

2 2 blank

blank blank 3

4 blank blank

5 5 blank

6 6 6

i have wriiten blank so that it appear formatted here
# 4  
Old 06-19-2009
I understood your requirement already.
Have you tried some code yourself? If yes, please share.

---------- Post updated 06-19-09 at 11:42 AM ---------- Previous update was 06-18-09 at 05:17 PM ----------

To start with, you can use the below code for comparing two files and inserting blanks.
Code:
sdiff file1 file2 | awk '{
if ($1==">")
   $1="                                                                  "
if ($2=="<")
   $2=" "
print
}'

# 5  
Old 06-19-2009
Thanks Rakesh i had tried some solutions but the script for it is turning out to be too long , also the diff ,sdiff, comm all work for two files very well but i am looking to compare three files, if i bring third file into comparison the output of sdiff turns out to be of no use

---------- Post updated at 04:57 AM ---------- Previous update was at 02:48 AM ----------

Rakesh i was able to think of a solution where in
cat a.txt b.txt c.txt > d.txt
sort d.txt | uniq > test

then run a for loop in test and check for the item in each of a.txt b.txt c.txt
if the item not present insert a blank in the file

Thanks for you response and inputs regarding the same.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Compare two files and show the mismatch columns

I need to compare two files and find the mismatch columns in it for csv and fixed width file. Eg: file1 c1,c2,c3,c4<----columnname 1,a,4,d 2,b,5,e 3,c,6,f file2 c1,c2,c3,c4<----columnname 3,x,7,f 2,y,8,e 1,z,9,d output c2,c3<---- mismatch columname a,4 x,7 b,5 or y,8 Ok with... (3 Replies)
Discussion started by: sabzR
3 Replies

2. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

Hello. I have a config file (/etc/my_config_file) which may content : # # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 # network interfaces to serve, comma delimited network_interface=eth0 # set this to the directory you want scanned. # * if have multiple... (6 Replies)
Discussion started by: jcdole
6 Replies

3. Shell Programming and Scripting

insert blank line between lines

Hello, I am trying to write a script that will count the number of characters for each line in a file and all the lines that have less than 80 characters and that are ending with a period, I want it to insert a blank line after them immediately. But, for whatever reason the condition if ]] is... (3 Replies)
Discussion started by: Pouchie1
3 Replies

4. Shell Programming and Scripting

Insert blank line if grep not found

Hi all, I've googling around forum regarding my prob, the nearest would same as thread tittled Insert blank line if grep not found, but she/he did not mention the solution, so I would like to request your help I've this task, to search in file2 based on pattern in file1 and output it to... (4 Replies)
Discussion started by: masterpiece
4 Replies

5. Shell Programming and Scripting

Compare selected columns of two files and print whole line with mismatch

hi! i researched about comparing two columns here and got an answer. but after examining my two files, i found out that the first columns of the two files are not unique with each other. all i want to compare is the 2nd and 3rd column. FILE 1: ABS 456 315 EBS 923 163 JYQ3 654 237 FILE 2:... (1 Reply)
Discussion started by: engr.jay
1 Replies

6. Shell Programming and Scripting

Compare two files and mismatch report

Hi I have two files f1 and f2 and comma separated file. I need to comapre two files by field by field and not by whole line. If they match then skip the line from both the files. If they don't match write the mismatch record from f1 to f3. Assume both the files are sorted on first field. ... (5 Replies)
Discussion started by: dgmm
5 Replies

7. Shell Programming and Scripting

Insert blank line in a file

I have a file with data as below : Heading 1 ------------- Heading 1 data1 Heading 1 data2 Heading 1 data3 Heading 1 data4 Heading 2 ------------- Heading 2 data1 Heading 2 data2 Heading 2 data3 Heading 2 data4 Heading 3 ------------- Heading 3 data1 Heading 3 data2 Heading 3... (2 Replies)
Discussion started by: yoursdivu
2 Replies

8. Shell Programming and Scripting

Edited: compare two files and print mismatch

Using unix shell script, how to compare two files and print lines with mismatch? Below are the requirements: 1. The number of lines on the two files is not the same. 2. The difference/mismatch can be found on the second or third column. 3. The comparison is not between line 1 of file 1 and line... (16 Replies)
Discussion started by: kingpeejay
16 Replies

9. Shell Programming and Scripting

insert text and add blank line

I need your help, I want to add a text every 2nd line and also a blank line after 3 line (In the output 2nd line is "changetype: modify" and every 4th line is blank line) Input file format dn: abc orclsourceobjectdn: abcd dn: bcd orclsourceobjectdn: bcda dn: cba orclsourceobjectdn:... (7 Replies)
Discussion started by: athidhi
7 Replies

10. Shell Programming and Scripting

Insert blank line if grep not found

Hello everyone... please help if you can -- I'm stumped. Making this work will save me hours of manual labor: I need to search file2 for pattern in file1. If pattern found append file2 line to file3. If pattern not found append a blank line to file3. file1 contents example: 123 456 789... (6 Replies)
Discussion started by: michieka
6 Replies
Login or Register to Ask a Question