Put the difference of two files in out file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Put the difference of two files in out file
# 1  
Old 03-25-2010
Put the difference of two files in out file

Hello,

I have two files file1 & file2 containing both lines (1 word per line). I need to extract the lines that are in file1 and not present in file2 and have the result in output file.

i.e :

user>cat file1
line1
line2
line3
line4
line5

user>cat file2
line1
line3
line5

The output file should only contain :

user>cat output
line2
line4

diff command is not fullfilling my nedd as it returns :
user>diff file1 file2
2d1
< line2
4,5d2
< line4
< line5
user>

Thank you
# 2  
Old 03-25-2010
Sort the files before using comm command
Code:
$ comm -23 file1 file2
line2
line4

# 3  
Old 03-25-2010
Thank you, it's working
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to put a difference calculation in my awk script ?

Hello, For my CGI, I have this script : #!/bin/bash echo "Content-type: text/html" echo "" echo ' <html> <head> <meta http-equiv="Content-Type" content="test/html"; charset=UTF-8"> <title> CLF MONITORING </title> <h1> FRAME... (4 Replies)
Discussion started by: Tim2424
4 Replies

2. Shell Programming and Scripting

awk script to find time difference between HTTP PUT and HTTP DELETE requests in access.log

Hi, I'm trying to write a script to determine the time gap between HTTP PUT and HTTP DELETE requests in the HTTP Servers access log. Normally client will do HTTP PUT to push content e.g. file_1.txt and 21 seconds later it will do HTTP DELETE, but sometimes the time varies causing some issues... (3 Replies)
Discussion started by: Juha
3 Replies

3. Shell Programming and Scripting

Difference between 2 files, one with 1 column and 2nd file with multiple columns

Hi, I need to find the difference between 2 files in unix and write the result in the new file File1: A B File2: X 123 hajkd Y 345 adjfka A 123 djafjhd B 678 dsndjks Output file: X 123 hajkd Y 345 adjfka Thanks. (6 Replies)
Discussion started by: nani1984
6 Replies

4. Shell Programming and Scripting

Comparing two files with numbers and taking difference in third file

Hi All, I have two files in the following format, with numbers being defined under columns(described by a set of headers) and rows(again defined by a set of identifiers) 2013 2013 Make200 Make201 Merc BMW Jpur Del ... (9 Replies)
Discussion started by: dev.devil.1983
9 Replies

5. Shell Programming and Scripting

Compare two CSV files and put the difference in third file with line no,field no and diff value.

I am having two csv files i need to compare these files and the output file should have the information of the differences at the field level. For Example, File 1: A,B,C,D,E,F 1,2,3,4,5,6 File 2: A,C,B,D,E,F 1,2,4,5,5,6 out put file: (12 Replies)
Discussion started by: karingulanagara
12 Replies

6. Shell Programming and Scripting

Comparing text in 2 files and output difference in another file.

I have 2 files of almost same text apart from 2,3 ending lines. Now I want to get that difference in another file. e.g file1.txt is Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_livecd-lv_root 18G 2.4G 15G 14% / tmpfs 504M ... (12 Replies)
Discussion started by: kashif.live
12 Replies

7. Shell Programming and Scripting

Combine two files and put it in .csv file

Hi Freinds I have two .txt file gem1.txt and gem2.txt, Sample gem1.txt abstract (1.0.0) actionmailer (2.3.5, 2.2.2) actionpack (2.3.5, 2.2.2) activerecord (2.3.5, 2.2.2) activerecord-oracle_enhanced-adapter (1.1.9) activerecord-sqlserver-adapter (2.3.4) activeresource (2.3.5, 2.2.2)... (3 Replies)
Discussion started by: ankit_view24
3 Replies

8. Shell Programming and Scripting

Find file size difference in two files using awk

Hi, Could anyone help me to solve this problem? I have two files "f1" and "f2" having 2 fields in each, a) file size and b) file name. The data are almost same in both the files except for few and new additional lines. Now, I have to find out and print the output as, the difference in the... (3 Replies)
Discussion started by: royalibrahim
3 Replies

9. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

10. Shell Programming and Scripting

compare two .dat files and if there is any difference pulled into a separate file

Hi, compare two .dat files and difference will be moved into separate file.if anybody having code for this please send asap. using diff command, i don't know how to write shell programming. and my first file is like this including Header and trailer 10Ç20060323Ç01(Header) 01ÇIÇbabuÇ3000 01ÇIÇbaluÇ4000... (1 Reply)
Discussion started by: kirankumar
1 Replies
Login or Register to Ask a Question