Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1157739
  • 博文数量: 241
  • 博客积分: 4385
  • 博客等级: 上校
  • 技术积分: 2383
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-07 23:13
文章分类

全部博文(241)

文章存档

2013年(1)

2012年(8)

2011年(62)

2010年(109)

2009年(61)

分类: LINUX

2010-11-12 10:21:55

新建两个示例文件如下:
hello.c

#include
int main(void)
{
    char msg[] = "Hello world!";
    
    puts(msg);
    printf("Welcome to use diff commond.\n");
    
    return 0;
}

hello_diff.c

#include
#include
int main(void)
{
    char msg[] = "Hello world,fome hello_diff.c";
    
    puts(msg);
    printf("hello_diff.c says,'Here you are,using diff.'\n");
    
    return 0;
}

1:普通输出
diff hello.c hello_diff.c

1a2
> #include
4c5
< char msg[] = "Hello world!";
---
> char msg[] = "Hello world,fome hello_diff.c";
7c8
< printf("Welcome to use diff commond.\n");
---
> printf("hello_diff.c says,'Here you are,using diff.'\n");

"1a2”表示后面的一个文件"hello_diff.c"比前面的一个文件"hello.c"多了一行,"4c5"表示第一个文件的第4行与第二个文件的第5行有区别
2:并排输出
diff hello.c hello_diff.c -y -W 130

#include                                          #include 
                                                  > #include
int main(void)                                    int main(void)
{                                                 {
        char msg[] = "Hello world!";              | char msg[] = "Hello world,fome hello_diff.c";

        puts(msg);                                puts(msg);
        printf("Welcome to use diff commond.\n"); | printf("Welcome to use diff commond.\n");

"-W 130”表示列宽设为130
3:上下文输出
diff hello.c hello_diff.c -c

*** hello.c 2010-11-12 09:59:41.000000000 +0800
--- hello_diff.c 2010-11-12 10:00:13.000000000 +0800
***************
*** 1,10 ****
  #include
  int main(void)
  {
! char msg[] = "Hello world!";
  
        puts(msg);
! printf("Welcome to use diff commond.\n");
  
        return 0;
  }
--- 1,11 ----
  #include
+ #include
  int main(void)
  {
! char msg[] = "Hello world,fome hello_diff.c";
  
        puts(msg);
! printf("hello_diff.c says,'Here you are,using diff.'\n");
  
        return 0;
  }

4:统一输出
diff hello.c hello_diff.c -u

--- hello.c 2010-11-12 09:59:41.000000000 +0800
+++ hello_diff.c 2010-11-12 10:00:13.000000000 +0800
@@ -1,10 +1,11 @@
 #include
+#include
 int main(void)
 {
- char msg[] = "Hello world!";
+ char msg[] = "Hello world,fome hello_diff.c";
 
        puts(msg);
- printf("Welcome to use diff commond.\n");
+ printf("hello_diff.c says,'Here you are,using diff.'\n");
 
        return 0;
 }


阅读(726) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~