diff two modified files?

diff two modified files?

Post by Markus Dehman » Sun, 27 Nov 2005 08:38:47



Is there an elegant/short way of diffing two modifications of files?  I
am using bash.

So, I have two files a and b, and I want to diff the first columns.
Normally, I'd do it like this:

awk '{print $1}' a > a.1
awk '{print $1}' b > b.1
diff a.1 b.1

But, is there a way to make it a oneliner, without having to produce
temporary files?

It would be nice if something like the following worked:
diff $(awk '{print $1}' a) $(awk '{print $1}' b)

Thanks!
Markus

 
 
 

diff two modified files?

Post by Janis Papanagno » Sun, 27 Nov 2005 08:48:11



> Is there an elegant/short way of diffing two modifications of files?  I
> am using bash.

> So, I have two files a and b, and I want to diff the first columns.
> Normally, I'd do it like this:

> awk '{print $1}' a > a.1
> awk '{print $1}' b > b.1
> diff a.1 b.1

> But, is there a way to make it a oneliner, without having to produce
> temporary files?

> It would be nice if something like the following worked:
> diff $(awk '{print $1}' a) $(awk '{print $1}' b)

Almost. Use process substitution...

   diff <(awk '{print $1}' a) <(awk '{print $1}' b)

Janis

 
 
 

diff two modified files?

Post by Markus Dehman » Sun, 27 Nov 2005 10:43:23




>> Is there an elegant/short way of diffing two modifications of files?  
>> I am using bash.

>> So, I have two files a and b, and I want to diff the first columns.
>> Normally, I'd do it like this:

>> awk '{print $1}' a > a.1
>> awk '{print $1}' b > b.1
>> diff a.1 b.1

>> But, is there a way to make it a oneliner, without having to produce
>> temporary files?

>> It would be nice if something like the following worked:
>> diff $(awk '{print $1}' a) $(awk '{print $1}' b)

> Almost. Use process substitution...

>   diff <(awk '{print $1}' a) <(awk '{print $1}' b)

Thanks!  I've never seen that before, but I think I'm gonna use it often
from now on ...

Markus

 
 
 

diff two modified files?

Post by Ed Morto » Sun, 27 Nov 2005 12:04:55



> Is there an elegant/short way of diffing two modifications of files?  I
> am using bash.

> So, I have two files a and b, and I want to diff the first columns.
> Normally, I'd do it like this:

> awk '{print $1}' a > a.1
> awk '{print $1}' b > b.1
> diff a.1 b.1

> But, is there a way to make it a oneliner, without having to produce
> temporary files?

> It would be nice if something like the following worked:
> diff $(awk '{print $1}' a) $(awk '{print $1}' b)

> Thanks!
> Markus

awk 'NR==FNR{f[FNR]=$1;next}f[FNR]!=$1{printf
"<\n%s\n>\n%s\n",f[FNR],$1}' a b

Regards,

        Ed.

 
 
 

1. Having trouble understanding diff. I need to comapre two files, and get a clean result!

I am trying to understand what diff is telling me.

If i have two files.

a        a
b        b
c        c
d        f
e        h
f         i
g        k
h        l
i         m
j         n

Then shouldn't diff tell me - using the "<" symbol, that some of the letters
in the first file, aren't in the second file...

$ diff a b
4,5d3
< d
< e
7d4
< g
10d6
< j
$

And if there are the same number of elements in the files, and they are in
order, it appears to be ok.

But, if the files are not in any order, in either or both files,
like this
File A:
a
b
c
d
e
f
g
h
i
j
k
l
m
n

File B:
a
l
c
f
b
i
k
e
m
n
o
p
q
r
s
t
$

Then the result is that it shows b for example as < and > ????  So it says
it missing from the first file, but also missing from the second file???

$ diff a b
2c2
< b
---
4,5d3
< d
< e
7,8c5
< g
< h
---
10d6
< j
12c8
< l
---
15c11,16
<
---
$

So how do I compare file A with file B, and return ONLY a list of elements
from file A that are NOT in file B.?

Dashed if I can find any too that will do it.

Thanks a million if anyone has a reasonable solution please..

Riobert

2. Linux, PGP and Sendmail.

3. Redirecting two input files to diff..

4. install linux on compaq presario 2100, help please!(cont)

5. "diff"ing two files

6. pppd-2.3b Does "deflate" work?

7. diff two files

8. Block I/O Enchancements, 2.5.1-pre2

9. Question about comparing two files- diff?

10. Looking for "diff"-like code to find differences between two files

11. Two different XF86Config for two diff Xservers?

12. how to compare (diff) files in two diretory structures

13. comparing two files using diff