This file is indexed.

/usr/share/doc/diffutils-doc/Output-Formats.html is in diffutils-doc 1:3.5-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual is for GNU Diffutils
(version 3.5, 4 August 2016),
and documents the GNU diff, diff3,
sdiff, and cmp commands for showing the
differences between files and the GNU patch command for
using their output to update files.

Copyright (C) 1992-1994, 1998, 2001-2002, 2004, 2006, 2009-2016 Free
Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled
"GNU Free Documentation License." -->
<!-- Created by GNU Texinfo 6.3, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Comparing and Merging Files: Output Formats</title>

<meta name="description" content="Comparing and Merging Files: Output Formats">
<meta name="keywords" content="Comparing and Merging Files: Output Formats">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Index.html#Index" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Incomplete-Lines.html#Incomplete-Lines" rel="next" title="Incomplete Lines">
<link href="Comparison.html#Binary" rel="prev" title="Binary">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<a name="Output-Formats"></a>
<div class="header">
<p>
Next: <a href="Incomplete-Lines.html#Incomplete-Lines" accesskey="n" rel="next">Incomplete Lines</a>, Previous: <a href="Comparison.html#Comparison" accesskey="p" rel="prev">Comparison</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="diff-Output-Formats"></a>
<h2 class="chapter">2 <code>diff</code> Output Formats</h2>
<a name="index-output-formats"></a>
<a name="index-format-of-diff-output"></a>

<p><code>diff</code> has several mutually exclusive options for output format.
The following sections describe each format, illustrating how
<code>diff</code> reports the differences between two sample input files.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Sample-diff-Input" accesskey="1">Sample diff Input</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Sample <code>diff</code> input files for examples.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Context" accesskey="2">Context</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Showing differences with the surrounding text.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Side-by-Side" accesskey="3">Side by Side</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Showing differences in two columns.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Normal" accesskey="4">Normal</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Showing differences without surrounding text.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Scripts" accesskey="5">Scripts</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Generating scripts for other programs.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#If_002dthen_002delse" accesskey="6">If-then-else</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Merging files with if-then-else.
</td></tr>
</table>

<hr>
<a name="Sample-diff-Input"></a>
<div class="header">
<p>
Next: <a href="#Context" accesskey="n" rel="next">Context</a>, Up: <a href="#Output-Formats" accesskey="u" rel="up">Output Formats</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Two-Sample-Input-Files"></a>
<h3 class="section">2.1 Two Sample Input Files</h3>
<a name="index-diff-sample-input"></a>
<a name="index-sample-input-for-diff"></a>

<p>Here are two sample files that we will use in numerous examples to
illustrate the output of <code>diff</code> and how various options can change
it.
</p>
<p>This is the file <samp>lao</samp>:
</p>
<div class="example">
<pre class="example">The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
The Nameless is the origin of Heaven and Earth;
The Named is the mother of all things.
Therefore let there always be non-being,
  so we may see their subtlety,
And let there always be being,
  so we may see their outcome.
The two are the same,
But after they are produced,
  they have different names.
</pre></div>

<p>This is the file <samp>tzu</samp>:
</p>
<div class="example">
<pre class="example">The Nameless is the origin of Heaven and Earth;
The named is the mother of all things.

Therefore let there always be non-being,
  so we may see their subtlety,
And let there always be being,
  so we may see their outcome.
The two are the same,
But after they are produced,
  they have different names.
They both may be called deep and profound.
Deeper and more profound,
The door of all subtleties!
</pre></div>

<p>In this example, the first hunk contains just the first two lines of
<samp>lao</samp>, the second hunk contains the fourth line of <samp>lao</samp>
opposing the second and third lines of <samp>tzu</samp>, and the last hunk
contains just the last three lines of <samp>tzu</samp>.
</p>
<hr>
<a name="Context"></a>
<div class="header">
<p>
Next: <a href="#Side-by-Side" accesskey="n" rel="next">Side by Side</a>, Previous: <a href="#Sample-diff-Input" accesskey="p" rel="prev">Sample diff Input</a>, Up: <a href="#Output-Formats" accesskey="u" rel="up">Output Formats</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Showing-Differences-in-Their-Context"></a>
<h3 class="section">2.2 Showing Differences in Their Context</h3>
<a name="index-context-output-format"></a>
<a name="index-_0021-output-format"></a>

<p>Usually, when you are looking at the differences between files, you will
also want to see the parts of the files near the lines that differ, to
help you understand exactly what has changed.  These nearby parts of the
files are called the <em>context</em>.
</p>
<p><acronym>GNU</acronym> <code>diff</code> provides two output formats that show context
around the differing lines: <em>context format</em> and <em>unified
format</em>.  It can optionally show in which function or section of the
file the differing lines are found.
</p>
<p>If you are distributing new versions of files to other people in the
form of <code>diff</code> output, you should use one of the output formats
that show context so that they can apply the diffs even if they have
made small changes of their own to the files.  <code>patch</code> can apply
the diffs in this case by searching in the files for the lines of
context around the differing lines; if those lines are actually a few
lines away from where the diff says they are, <code>patch</code> can adjust
the line numbers accordingly and still apply the diff correctly.
See <a href="Merging-with-patch.html#Imperfect">Imperfect</a>, for more information on using <code>patch</code> to apply
imperfect diffs.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Context-Format" accesskey="1">Context Format</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">An output format that shows surrounding lines.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Unified-Format" accesskey="2">Unified Format</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A more compact output format that shows context.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Sections" accesskey="3">Sections</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Showing which sections of the files differences are in.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Alternate-Names" accesskey="4">Alternate Names</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Showing alternate file names in context headers.
</td></tr>
</table>

<hr>
<a name="Context-Format"></a>
<div class="header">
<p>
Next: <a href="#Unified-Format" accesskey="n" rel="next">Unified Format</a>, Up: <a href="#Context" accesskey="u" rel="up">Context</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Context-Format-1"></a>
<h4 class="subsection">2.2.1 Context Format</h4>

<p>The context output format shows several lines of context around the
lines that differ.  It is the standard format for distributing updates
to source code.
</p>
<p>To select this output format, use the
<samp>--context<span class="roman">[</span>=<var>lines</var><span class="roman">]</span></samp> (<samp>-C <var>lines</var></samp>)
or <samp>-c</samp> option.  The
argument <var>lines</var> that some of these options take is the number of
lines of context to show.  If you do not specify <var>lines</var>, it
defaults to three.  For proper operation, <code>patch</code> typically needs
at least two lines of context.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Example-Context" accesskey="1">Example Context</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Sample output in context format.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Less-Context" accesskey="2">Less Context</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Another sample with less context.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Detailed-Context" accesskey="3">Detailed Context</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A detailed description of the context output format.
</td></tr>
</table>

<hr>
<a name="Example-Context"></a>
<div class="header">
<p>
Next: <a href="#Less-Context" accesskey="n" rel="next">Less Context</a>, Up: <a href="#Context-Format" accesskey="u" rel="up">Context Format</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="An-Example-of-Context-Format"></a>
<h4 class="subsubsection">2.2.1.1 An Example of Context Format</h4>

<p>Here is the output of &lsquo;<samp>diff -c lao tzu</samp>&rsquo; (see <a href="#Sample-diff-Input">Sample diff Input</a>,
for the complete contents of the two files).  Notice that up to three
lines that are not different are shown around each line that is
different; they are the context lines.  Also notice that the first two
hunks have run together, because their contents overlap.
</p>
<div class="example">
<pre class="example">*** lao	2002-02-21 23:30:39.942229878 -0800
--- tzu	2002-02-21 23:30:50.442260588 -0800
***************
*** 1,7 ****
- The Way that can be told of is not the eternal Way;
- The name that can be named is not the eternal name.
  The Nameless is the origin of Heaven and Earth;
! The Named is the mother of all things.
  Therefore let there always be non-being,
    so we may see their subtlety,
  And let there always be being,
--- 1,6 ----
  The Nameless is the origin of Heaven and Earth;
! The named is the mother of all things.
! 
  Therefore let there always be non-being,
    so we may see their subtlety,
  And let there always be being,
***************
*** 9,11 ****
--- 8,13 ----
  The two are the same,
  But after they are produced,
    they have different names.
+ They both may be called deep and profound.
+ Deeper and more profound,
+ The door of all subtleties!
</pre></div>

<hr>
<a name="Less-Context"></a>
<div class="header">
<p>
Next: <a href="#Detailed-Context" accesskey="n" rel="next">Detailed Context</a>, Previous: <a href="#Example-Context" accesskey="p" rel="prev">Example Context</a>, Up: <a href="#Context-Format" accesskey="u" rel="up">Context Format</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="An-Example-of-Context-Format-with-Less-Context"></a>
<h4 class="subsubsection">2.2.1.2 An Example of Context Format with Less Context</h4>

<p>Here is the output of &lsquo;<samp>diff -C 1 lao tzu</samp>&rsquo; (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files).  Notice that at
most one context line is reported here.
</p>
<div class="example">
<pre class="example">*** lao	2002-02-21 23:30:39.942229878 -0800
--- tzu	2002-02-21 23:30:50.442260588 -0800
***************
*** 1,5 ****
- The Way that can be told of is not the eternal Way;
- The name that can be named is not the eternal name.
  The Nameless is the origin of Heaven and Earth;
! The Named is the mother of all things.
  Therefore let there always be non-being,
--- 1,4 ----
  The Nameless is the origin of Heaven and Earth;
! The named is the mother of all things.
! 
  Therefore let there always be non-being,
***************
*** 11 ****
--- 10,13 ----
    they have different names.
+ They both may be called deep and profound.
+ Deeper and more profound,
+ The door of all subtleties!
</pre></div>

<hr>
<a name="Detailed-Context"></a>
<div class="header">
<p>
Previous: <a href="#Less-Context" accesskey="p" rel="prev">Less Context</a>, Up: <a href="#Context-Format" accesskey="u" rel="up">Context Format</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Detailed-Description-of-Context-Format"></a>
<h4 class="subsubsection">2.2.1.3 Detailed Description of Context Format</h4>

<p>The context output format starts with a two-line header, which looks
like this:
</p>
<div class="example">
<pre class="example">*** <var>from-file</var> <var>from-file-modification-time</var>
--- <var>to-file</var> <var>to-file-modification time</var>
</pre></div>

<p><a name="index-LC_005fTIME"></a>
<a name="index-time-stamp-format_002c-context-diffs"></a>
The time stamp normally looks like &lsquo;<samp>2002-02-21 23:30:39.942229878
-0800</samp>&rsquo; to indicate the date, time with fractional seconds, and time
zone in <a href="ftp://ftp.isi.edu/in-notes/rfc2822.txt">Internet RFC
2822 format</a>.  (The fractional seconds are omitted on hosts that do
not support fractional time stamps.)  However, a traditional time
stamp like &lsquo;<samp>Thu Feb 21 23:30:39 2002</samp>&rsquo; is used if the
<code>LC_TIME</code> locale category is either &lsquo;<samp>C</samp>&rsquo; or &lsquo;<samp>POSIX</samp>&rsquo;.
</p>
<p>You can change the header&rsquo;s content with the
<samp>--label=<var>label</var></samp> option; see <a href="#Alternate-Names">Alternate Names</a>.
</p>
<p>Next come one or more hunks of differences; each hunk shows one area
where the files differ.  Context format hunks look like this:
</p>
<div class="example">
<pre class="example">***************
*** <var>from-file-line-numbers</var> ****
  <var>from-file-line</var>
  <var>from-file-line</var>&hellip;
--- <var>to-file-line-numbers</var> ----
  <var>to-file-line</var>
  <var>to-file-line</var>&hellip;
</pre></div>

<p>If a hunk contains two or more lines, its line numbers look like
&lsquo;<samp><var>start</var>,<var>end</var></samp>&rsquo;.  Otherwise only its end line number
appears.  An empty hunk is considered to end at the line that precedes
the hunk.
</p>
<p>The lines of context around the lines that differ start with two space
characters.  The lines that differ between the two files start with one
of the following indicator characters, followed by a space character:
</p>
<dl compact="compact">
<dt>&lsquo;<samp>!</samp>&rsquo;</dt>
<dd><p>A line that is part of a group of one or more lines that changed between
the two files.  There is a corresponding group of lines marked with
&lsquo;<samp>!</samp>&rsquo; in the part of this hunk for the other file.
</p>
</dd>
<dt>&lsquo;<samp>+</samp>&rsquo;</dt>
<dd><p>An &ldquo;inserted&rdquo; line in the second file that corresponds to nothing in
the first file.
</p>
</dd>
<dt>&lsquo;<samp>-</samp>&rsquo;</dt>
<dd><p>A &ldquo;deleted&rdquo; line in the first file that corresponds to nothing in the
second file.
</p></dd>
</dl>

<p>If all of the changes in a hunk are insertions, the lines of
<var>from-file</var> are omitted.  If all of the changes are deletions, the
lines of <var>to-file</var> are omitted.
</p>
<hr>
<a name="Unified-Format"></a>
<div class="header">
<p>
Next: <a href="#Sections" accesskey="n" rel="next">Sections</a>, Previous: <a href="#Context-Format" accesskey="p" rel="prev">Context Format</a>, Up: <a href="#Context" accesskey="u" rel="up">Context</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Unified-Format-1"></a>
<h4 class="subsection">2.2.2 Unified Format</h4>
<a name="index-unified-output-format"></a>
<a name="index-_002b_002d-output-format"></a>

<p>The unified output format is a variation on the context format that is
more compact because it omits redundant context lines.  To select this
output format, use the
<samp>--unified<span class="roman">[</span>=<var>lines</var><span class="roman">]</span></samp> (<samp>-U <var>lines</var></samp>),
or <samp>-u</samp> option.
The argument <var>lines</var> is the number of lines of context to show.
When it is not given, it defaults to three.
</p>
<p>At present, only <acronym>GNU</acronym> <code>diff</code> can produce this format and
only <acronym>GNU</acronym> <code>patch</code> can automatically apply diffs in this
format.  For proper operation, <code>patch</code> typically needs at
least three lines of context.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Example-Unified" accesskey="1">Example Unified</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Sample output in unified format.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Detailed-Unified" accesskey="2">Detailed Unified</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A detailed description of unified format.
</td></tr>
</table>

<hr>
<a name="Example-Unified"></a>
<div class="header">
<p>
Next: <a href="#Detailed-Unified" accesskey="n" rel="next">Detailed Unified</a>, Up: <a href="#Unified-Format" accesskey="u" rel="up">Unified Format</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="An-Example-of-Unified-Format"></a>
<h4 class="subsubsection">2.2.2.1 An Example of Unified Format</h4>

<p>Here is the output of the command &lsquo;<samp>diff -u lao tzu</samp>&rsquo;
(see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
</p>
<div class="example">
<pre class="example">--- lao	2002-02-21 23:30:39.942229878 -0800
+++ tzu	2002-02-21 23:30:50.442260588 -0800
@@ -1,7 +1,6 @@
-The Way that can be told of is not the eternal Way;
-The name that can be named is not the eternal name.
 The Nameless is the origin of Heaven and Earth;
-The Named is the mother of all things.
+The named is the mother of all things.
+
 Therefore let there always be non-being,
   so we may see their subtlety,
 And let there always be being,
@@ -9,3 +8,6 @@
 The two are the same,
 But after they are produced,
   they have different names.
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties!
</pre></div>

<hr>
<a name="Detailed-Unified"></a>
<div class="header">
<p>
Previous: <a href="#Example-Unified" accesskey="p" rel="prev">Example Unified</a>, Up: <a href="#Unified-Format" accesskey="u" rel="up">Unified Format</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Detailed-Description-of-Unified-Format"></a>
<h4 class="subsubsection">2.2.2.2 Detailed Description of Unified Format</h4>

<p>The unified output format starts with a two-line header, which looks
like this:
</p>
<div class="example">
<pre class="example">--- <var>from-file</var> <var>from-file-modification-time</var>
+++ <var>to-file</var> <var>to-file-modification-time</var>
</pre></div>

<p><a name="index-time-stamp-format_002c-unified-diffs"></a>
The time stamp looks like &lsquo;<samp>2002-02-21 23:30:39.942229878 -0800</samp>&rsquo;
to indicate the date, time with fractional seconds, and time zone.
The fractional seconds are omitted on hosts that do not support
fractional time stamps.
</p>
<p>You can change the header&rsquo;s content with the
<samp>--label=<var>label</var></samp> option. See <a href="#Alternate-Names">Alternate Names</a>.
</p>
<p>Next come one or more hunks of differences; each hunk shows one area
where the files differ.  Unified format hunks look like this:
</p>
<div class="example">
<pre class="example">@@ <var>from-file-line-numbers</var> <var>to-file-line-numbers</var> @@
 <var>line-from-either-file</var>
 <var>line-from-either-file</var>&hellip;
</pre></div>

<p>If a hunk contains just one line, only its start line number appears.
Otherwise its line numbers look like &lsquo;<samp><var>start</var>,<var>count</var></samp>&rsquo;.
An empty hunk is considered to start at the line that follows the hunk.
</p>
<p>If a hunk and its context contain two or more lines, its
line numbers look like &lsquo;<samp><var>start</var>,<var>count</var></samp>&rsquo;.  Otherwise only
its end line number appears.  An empty hunk is considered to end at
the line that precedes the hunk.
</p>
<p>The lines common to both files begin with a space character.  The lines
that actually differ between the two files have one of the following
indicator characters in the left print column:
</p>
<dl compact="compact">
<dt>&lsquo;<samp>+</samp>&rsquo;</dt>
<dd><p>A line was added here to the first file.
</p>
</dd>
<dt>&lsquo;<samp>-</samp>&rsquo;</dt>
<dd><p>A line was removed here from the first file.
</p></dd>
</dl>

<hr>
<a name="Sections"></a>
<div class="header">
<p>
Next: <a href="#Alternate-Names" accesskey="n" rel="next">Alternate Names</a>, Previous: <a href="#Unified-Format" accesskey="p" rel="prev">Unified Format</a>, Up: <a href="#Context" accesskey="u" rel="up">Context</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Showing-Which-Sections-Differences-Are-in"></a>
<h4 class="subsection">2.2.3 Showing Which Sections Differences Are in</h4>
<a name="index-headings"></a>
<a name="index-section-headings"></a>

<p>Sometimes you might want to know which part of the files each change
falls in.  If the files are source code, this could mean which
function was changed.  If the files are documents, it could mean which
chapter or appendix was changed.  <acronym>GNU</acronym> <code>diff</code> can
show this by displaying the nearest section heading line that precedes
the differing lines.  Which lines are &ldquo;section headings&rdquo; is
determined by a regular expression.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Specified-Headings" accesskey="1">Specified Headings</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Showing headings that match regular expressions.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#C-Function-Headings" accesskey="2">C Function Headings</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Showing headings of C functions.
</td></tr>
</table>

<hr>
<a name="Specified-Headings"></a>
<div class="header">
<p>
Next: <a href="#C-Function-Headings" accesskey="n" rel="next">C Function Headings</a>, Up: <a href="#Sections" accesskey="u" rel="up">Sections</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Showing-Lines-That-Match-Regular-Expressions"></a>
<h4 class="subsubsection">2.2.3.1 Showing Lines That Match Regular Expressions</h4>
<a name="index-specified-headings"></a>
<a name="index-regular-expression-matching-headings"></a>

<p>To show in which sections differences occur for files that are not
source code for C or similar languages, use the
<samp>--show-function-line=<var>regexp</var></samp> (<samp>-F <var>regexp</var></samp>) option.
<code>diff</code>
considers lines that match the <code>grep</code>-style regular expression
<var>regexp</var> to be the beginning
of a section of the file.  Here are suggested regular expressions for
some common languages:
</p>
<dl compact="compact">
<dt>&lsquo;<samp>^[[:alpha:]$_]</samp>&rsquo;</dt>
<dd><p>C, C++, Prolog
</p></dd>
<dt>&lsquo;<samp>^(</samp>&rsquo;</dt>
<dd><p>Lisp
</p></dd>
<dt>&lsquo;<samp>^@node</samp>&rsquo;</dt>
<dd><p>Texinfo
</p></dd>
</dl>

<p>This option does not automatically select an output format; in order to
use it, you must select the context format (see <a href="#Context-Format">Context Format</a>) or
unified format (see <a href="#Unified-Format">Unified Format</a>).  In other output formats it
has no effect.
</p>
<p>The <samp>--show-function-line</samp> (<samp>-F</samp>) option finds the nearest
unchanged line that precedes each hunk of differences and matches the
given regular expression.  Then it adds that line to the end of the
line of asterisks in the context format, or to the &lsquo;<samp>@@</samp>&rsquo; line in
unified format.  If no matching line exists, this option leaves the output for
that hunk unchanged.  If that line is more than 40 characters long, it
outputs only the first 40 characters.  You can specify more than one
regular expression for such lines; <code>diff</code> tries to match each line
against each regular expression, starting with the last one given.  This
means that you can use <samp>-p</samp> and <samp>-F</samp> together, if you wish.
</p>
<hr>
<a name="C-Function-Headings"></a>
<div class="header">
<p>
Previous: <a href="#Specified-Headings" accesskey="p" rel="prev">Specified Headings</a>, Up: <a href="#Sections" accesskey="u" rel="up">Sections</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Showing-C-Function-Headings"></a>
<h4 class="subsubsection">2.2.3.2 Showing C Function Headings</h4>
<a name="index-C-function-headings"></a>
<a name="index-function-headings_002c-C"></a>

<p>To show in which functions differences occur for C and similar
languages, you can use the <samp>--show-c-function</samp> (<samp>-p</samp>) option.
This option automatically defaults to the context output format
(see <a href="#Context-Format">Context Format</a>), with the default number of lines of context.
You can override that number with <samp>-C <var>lines</var></samp> elsewhere in the
command line.  You can override both the format and the number with
<samp>-U <var>lines</var></samp> elsewhere in the command line.
</p>
<p>The <samp>--show-c-function</samp> (<samp>-p</samp>) option is equivalent to
<samp>-F '^[[:alpha:]$_]'</samp> if the unified format is specified, otherwise
<samp>-c -F '^[[:alpha:]$_]'</samp> (see <a href="#Specified-Headings">Specified Headings</a>).  <acronym>GNU</acronym>
<code>diff</code> provides this option for the sake of convenience.
</p>
<hr>
<a name="Alternate-Names"></a>
<div class="header">
<p>
Previous: <a href="#Sections" accesskey="p" rel="prev">Sections</a>, Up: <a href="#Context" accesskey="u" rel="up">Context</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Showing-Alternate-File-Names"></a>
<h4 class="subsection">2.2.4 Showing Alternate File Names</h4>
<a name="index-alternate-file-names"></a>
<a name="index-file-name-alternates"></a>

<p>If you are comparing two files that have meaningless or uninformative
names, you might want <code>diff</code> to show alternate names in the header
of the context and unified output formats.  To do this, use the
<samp>--label=<var>label</var></samp> option.  The first time
you give this option, its argument replaces the name and date of the
first file in the header; the second time, its argument replaces the
name and date of the second file.  If you give this option more than
twice, <code>diff</code> reports an error.  The <samp>--label</samp> option does not
affect the file names in the <code>pr</code> header when the <samp>-l</samp> or
<samp>--paginate</samp> option is used (see <a href="Adjusting-Output.html#Pagination">Pagination</a>).
</p>
<p>Here are the first two lines of the output from &lsquo;<samp>diff -C 2
--label=original --label=modified lao tzu</samp>&rsquo;:
</p>
<div class="example">
<pre class="example">*** original
--- modified
</pre></div>

<hr>
<a name="Side-by-Side"></a>
<div class="header">
<p>
Next: <a href="#Normal" accesskey="n" rel="next">Normal</a>, Previous: <a href="#Context" accesskey="p" rel="prev">Context</a>, Up: <a href="#Output-Formats" accesskey="u" rel="up">Output Formats</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Showing-Differences-Side-by-Side"></a>
<h3 class="section">2.3 Showing Differences Side by Side</h3>
<a name="index-side-by-side"></a>
<a name="index-two_002dcolumn-output"></a>
<a name="index-columnar-output"></a>

<p><code>diff</code> can produce a side by side difference listing of two files.
The files are listed in two columns with a gutter between them.  The
gutter contains one of the following markers:
</p>
<dl compact="compact">
<dt>white space</dt>
<dd><p>The corresponding lines are in common.  That is, either the lines are
identical, or the difference is ignored because of one of the
<samp>--ignore</samp> options (see <a href="Comparison.html#White-Space">White Space</a>).
</p>
</dd>
<dt>&lsquo;<samp>|</samp>&rsquo;</dt>
<dd><p>The corresponding lines differ, and they are either both complete
or both incomplete.
</p>
</dd>
<dt>&lsquo;<samp>&lt;</samp>&rsquo;</dt>
<dd><p>The files differ and only the first file contains the line.
</p>
</dd>
<dt>&lsquo;<samp>&gt;</samp>&rsquo;</dt>
<dd><p>The files differ and only the second file contains the line.
</p>
</dd>
<dt>&lsquo;<samp>(</samp>&rsquo;</dt>
<dd><p>Only the first file contains the line, but the difference is ignored.
</p>
</dd>
<dt>&lsquo;<samp>)</samp>&rsquo;</dt>
<dd><p>Only the second file contains the line, but the difference is ignored.
</p>
</dd>
<dt>&lsquo;<samp>\</samp>&rsquo;</dt>
<dd><p>The corresponding lines differ, and only the first line is incomplete.
</p>
</dd>
<dt>&lsquo;<samp>/</samp>&rsquo;</dt>
<dd><p>The corresponding lines differ, and only the second line is incomplete.
</p></dd>
</dl>

<p>Normally, an output line is incomplete if and only if the lines that it
contains are incomplete.  See <a href="Incomplete-Lines.html#Incomplete-Lines">Incomplete Lines</a>.  However, when an
output line represents two differing lines, one might be incomplete
while the other is not.  In this case, the output line is complete,
but its the gutter is marked &lsquo;<samp>\</samp>&rsquo; if the first line is incomplete,
&lsquo;<samp>/</samp>&rsquo; if the second line is.
</p>
<p>Side by side format is sometimes easiest to read, but it has limitations.
It generates much wider output than usual, and truncates lines that are
too long to fit.  Also, it relies on lining up output more heavily than
usual, so its output looks particularly bad if you use varying
width fonts, nonstandard tab stops, or nonprinting characters.
</p>
<p>You can use the <code>sdiff</code> command to interactively merge side by side
differences.  See <a href="Interactive-Merging.html#Interactive-Merging">Interactive Merging</a>, for more information on merging files.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Side-by-Side-Format" accesskey="1">Side by Side Format</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Controlling side by side output format.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Example-Side-by-Side" accesskey="2">Example Side by Side</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Sample side by side output.
</td></tr>
</table>

<hr>
<a name="Side-by-Side-Format"></a>
<div class="header">
<p>
Next: <a href="#Example-Side-by-Side" accesskey="n" rel="next">Example Side by Side</a>, Up: <a href="#Side-by-Side" accesskey="u" rel="up">Side by Side</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Controlling-Side-by-Side-Format"></a>
<h4 class="subsection">2.3.1 Controlling Side by Side Format</h4>
<a name="index-side-by-side-format"></a>

<p>The <samp>--side-by-side</samp> (<samp>-y</samp>) option selects side by side
format.  Because side by side output lines contain two input lines, the
output is wider than usual: normally 130 print columns, which can fit
onto a traditional printer line.  You can set the width of the output
with the <samp>--width=<var>columns</var></samp> (<samp>-W <var>columns</var></samp>)
option.  The output is split into two halves of equal width, separated by a
small gutter to mark differences; the right half is aligned to a tab
stop so that tabs line up.  Input lines that are too long to fit in half
of an output line are truncated for output.
</p>
<p>The <samp>--left-column</samp> option prints only the left column of two
common lines.  The <samp>--suppress-common-lines</samp> option suppresses
common lines entirely.
</p>
<hr>
<a name="Example-Side-by-Side"></a>
<div class="header">
<p>
Previous: <a href="#Side-by-Side-Format" accesskey="p" rel="prev">Side by Side Format</a>, Up: <a href="#Side-by-Side" accesskey="u" rel="up">Side by Side</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="An-Example-of-Side-by-Side-Format"></a>
<h4 class="subsection">2.3.2 An Example of Side by Side Format</h4>

<p>Here is the output of the command &lsquo;<samp>diff -y -W 72 lao tzu</samp>&rsquo;
(see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files).
</p>
<div class="example">
<pre class="example">The Way that can be told of is n   &lt;
The name that can be named is no   &lt;
The Nameless is the origin of He        The Nameless is the origin of He
The Named is the mother of all t   |    The named is the mother of all t
                                   &gt;
Therefore let there always be no        Therefore let there always be no
  so we may see their subtlety,           so we may see their subtlety,
And let there always be being,          And let there always be being,
  so we may see their outcome.            so we may see their outcome.
The two are the same,                   The two are the same,
But after they are produced,            But after they are produced,
  they have different names.              they have different names.
                                   &gt;    They both may be called deep and
                                   &gt;    Deeper and more profound,
                                   &gt;    The door of all subtleties!
</pre></div>

<hr>
<a name="Normal"></a>
<div class="header">
<p>
Next: <a href="#Scripts" accesskey="n" rel="next">Scripts</a>, Previous: <a href="#Side-by-Side" accesskey="p" rel="prev">Side by Side</a>, Up: <a href="#Output-Formats" accesskey="u" rel="up">Output Formats</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Showing-Differences-Without-Context"></a>
<h3 class="section">2.4 Showing Differences Without Context</h3>
<a name="index-normal-output-format"></a>
<a name="index-_003c-output-format"></a>

<p>The &ldquo;normal&rdquo; <code>diff</code> output format shows each hunk of differences
without any surrounding context.  Sometimes such output is the clearest
way to see how lines have changed, without the clutter of nearby
unchanged lines (although you can get similar results with the context
or unified formats by using 0 lines of context).  However, this format
is no longer widely used for sending out patches; for that purpose, the
context format (see <a href="#Context-Format">Context Format</a>) and the unified format
(see <a href="#Unified-Format">Unified Format</a>) are superior.  Normal format is the default for
compatibility with older versions of <code>diff</code> and the <acronym>POSIX</acronym>
standard.  Use the <samp>--normal</samp> option to select this output
format explicitly.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Example-Normal" accesskey="1">Example Normal</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Sample output in the normal format.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Detailed-Normal" accesskey="2">Detailed Normal</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A detailed description of normal output format.
</td></tr>
</table>

<hr>
<a name="Example-Normal"></a>
<div class="header">
<p>
Next: <a href="#Detailed-Normal" accesskey="n" rel="next">Detailed Normal</a>, Up: <a href="#Normal" accesskey="u" rel="up">Normal</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="An-Example-of-Normal-Format"></a>
<h4 class="subsection">2.4.1 An Example of Normal Format</h4>

<p>Here is the output of the command &lsquo;<samp>diff lao tzu</samp>&rsquo;
(see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files).
Notice that it shows only the lines that are different between the two
files.
</p>
<div class="example">
<pre class="example">1,2d0
&lt; The Way that can be told of is not the eternal Way;
&lt; The name that can be named is not the eternal name.
4c2,3
&lt; The Named is the mother of all things.
---
&gt; The named is the mother of all things.
&gt; 
11a11,13
&gt; They both may be called deep and profound.
&gt; Deeper and more profound,
&gt; The door of all subtleties!
</pre></div>

<hr>
<a name="Detailed-Normal"></a>
<div class="header">
<p>
Previous: <a href="#Example-Normal" accesskey="p" rel="prev">Example Normal</a>, Up: <a href="#Normal" accesskey="u" rel="up">Normal</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Detailed-Description-of-Normal-Format"></a>
<h4 class="subsection">2.4.2 Detailed Description of Normal Format</h4>

<p>The normal output format consists of one or more hunks of differences;
each hunk shows one area where the files differ.  Normal format hunks
look like this:
</p>
<div class="example">
<pre class="example"><var>change-command</var>
&lt; <var>from-file-line</var>
&lt; <var>from-file-line</var>&hellip;
---
&gt; <var>to-file-line</var>
&gt; <var>to-file-line</var>&hellip;
</pre></div>

<p>There are three types of change commands.  Each consists of a line
number or comma-separated range of lines in the first file, a single
character indicating the kind of change to make, and a line number or
comma-separated range of lines in the second file.  All line numbers are
the original line numbers in each file.  The types of change commands
are:
</p>
<dl compact="compact">
<dt>&lsquo;<samp><var>l</var>a<var>r</var></samp>&rsquo;</dt>
<dd><p>Add the lines in range <var>r</var> of the second file after line <var>l</var> of
the first file.  For example, &lsquo;<samp>8a12,15</samp>&rsquo; means append lines 12&ndash;15
of file 2 after line 8 of file 1; or, if changing file 2 into file 1,
delete lines 12&ndash;15 of file 2.
</p>
</dd>
<dt>&lsquo;<samp><var>f</var>c<var>t</var></samp>&rsquo;</dt>
<dd><p>Replace the lines in range <var>f</var> of the first file with lines in range
<var>t</var> of the second file.  This is like a combined add and delete, but
more compact.  For example, &lsquo;<samp>5,7c8,10</samp>&rsquo; means change lines 5&ndash;7 of
file 1 to read as lines 8&ndash;10 of file 2; or, if changing file 2 into
file 1, change lines 8&ndash;10 of file 2 to read as lines 5&ndash;7 of file 1.
</p>
</dd>
<dt>&lsquo;<samp><var>r</var>d<var>l</var></samp>&rsquo;</dt>
<dd><p>Delete the lines in range <var>r</var> from the first file; line <var>l</var> is where
they would have appeared in the second file had they not been deleted.
For example, &lsquo;<samp>5,7d3</samp>&rsquo; means delete lines 5&ndash;7 of file 1; or, if
changing file 2 into file 1, append lines 5&ndash;7 of file 1 after line 3 of
file 2.
</p></dd>
</dl>

<hr>
<a name="Scripts"></a>
<div class="header">
<p>
Next: <a href="#If_002dthen_002delse" accesskey="n" rel="next">If-then-else</a>, Previous: <a href="#Normal" accesskey="p" rel="prev">Normal</a>, Up: <a href="#Output-Formats" accesskey="u" rel="up">Output Formats</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Making-Edit-Scripts"></a>
<h3 class="section">2.5 Making Edit Scripts</h3>
<a name="index-script-output-formats"></a>

<p>Several output modes produce command scripts for editing <var>from-file</var>
to produce <var>to-file</var>.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#ed-Scripts" accesskey="1">ed Scripts</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Using <code>diff</code> to produce commands for <code>ed</code>.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Forward-ed" accesskey="2">Forward ed</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Making forward <code>ed</code> scripts.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#RCS" accesskey="3">RCS</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A special <code>diff</code> output format used by <acronym>RCS</acronym>.
</td></tr>
</table>

<hr>
<a name="ed-Scripts"></a>
<div class="header">
<p>
Next: <a href="#Forward-ed" accesskey="n" rel="next">Forward ed</a>, Up: <a href="#Scripts" accesskey="u" rel="up">Scripts</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="ed-Scripts-1"></a>
<h4 class="subsection">2.5.1 <code>ed</code> Scripts</h4>
<a name="index-ed-script-output-format"></a>

<p><code>diff</code> can produce commands that direct the <code>ed</code> text editor
to change the first file into the second file.  Long ago, this was the
only output mode that was suitable for editing one file into another
automatically; today, with <code>patch</code>, it is almost obsolete.  Use the
<samp>--ed</samp> (<samp>-e</samp>) option to select this output format.
</p>
<p>Like the normal format (see <a href="#Normal">Normal</a>), this output format does not
show any context; unlike the normal format, it does not include the
information necessary to apply the diff in reverse (to produce the first
file if all you have is the second file and the diff).
</p>
<p>If the file <samp>d</samp> contains the output of &lsquo;<samp>diff -e old new</samp>&rsquo;, then
the command &lsquo;<samp>(cat d &amp;&amp; echo w) | ed - old</samp>&rsquo; edits <samp>old</samp> to make
it a copy of <samp>new</samp>.  More generally, if <samp>d1</samp>, <samp>d2</samp>,
&hellip;, <samp>dN</samp> contain the outputs of &lsquo;<samp>diff -e old new1</samp>&rsquo;,
&lsquo;<samp>diff -e new1 new2</samp>&rsquo;, &hellip;, &lsquo;<samp>diff -e newN-1 newN</samp>&rsquo;,
respectively, then the command &lsquo;<samp>(cat d1 d2 &hellip; dN &amp;&amp; echo w) |
ed - old</samp>&rsquo; edits <samp>old</samp> to make it a copy of <samp>newN</samp>.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Example-ed" accesskey="1">Example ed</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A sample <code>ed</code> script.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Detailed-ed" accesskey="2">Detailed ed</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A detailed description of <code>ed</code> format.
</td></tr>
</table>

<hr>
<a name="Example-ed"></a>
<div class="header">
<p>
Next: <a href="#Detailed-ed" accesskey="n" rel="next">Detailed ed</a>, Up: <a href="#ed-Scripts" accesskey="u" rel="up">ed Scripts</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Example-ed-Script"></a>
<h4 class="subsubsection">2.5.1.1 Example <code>ed</code> Script</h4>

<p>Here is the output of &lsquo;<samp>diff -e lao tzu</samp>&rsquo; (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
</p>
<div class="example">
<pre class="example">11a
They both may be called deep and profound.
Deeper and more profound,
The door of all subtleties!
.
4c
The named is the mother of all things.

.
1,2d
</pre></div>

<hr>
<a name="Detailed-ed"></a>
<div class="header">
<p>
Previous: <a href="#Example-ed" accesskey="p" rel="prev">Example ed</a>, Up: <a href="#ed-Scripts" accesskey="u" rel="up">ed Scripts</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Detailed-Description-of-ed-Format"></a>
<h4 class="subsubsection">2.5.1.2 Detailed Description of <code>ed</code> Format</h4>

<p>The <code>ed</code> output format consists of one or more hunks of
differences.  The changes closest to the ends of the files come first so
that commands that change the number of lines do not affect how
<code>ed</code> interprets line numbers in succeeding commands.  <code>ed</code>
format hunks look like this:
</p>
<div class="example">
<pre class="example"><var>change-command</var>
<var>to-file-line</var>
<var>to-file-line</var>&hellip;
.
</pre></div>

<p>Because <code>ed</code> uses a single period on a line to indicate the
end of input, <acronym>GNU</acronym> <code>diff</code> protects lines of changes
that contain a single period on a line by writing two periods instead,
then writing a subsequent <code>ed</code> command to change the two
periods into one.  The <code>ed</code> format cannot represent an
incomplete line, so if the second file ends in a changed incomplete
line, <code>diff</code> reports an error and then pretends that a newline
was appended.
</p>
<p>There are three types of change commands.  Each consists of a line
number or comma-separated range of lines in the first file and a single
character indicating the kind of change to make.  All line numbers are
the original line numbers in the file.  The types of change commands
are:
</p>
<dl compact="compact">
<dt>&lsquo;<samp><var>l</var>a</samp>&rsquo;</dt>
<dd><p>Add text from the second file after line <var>l</var> in the first file.  For
example, &lsquo;<samp>8a</samp>&rsquo; means to add the following lines after line 8 of file
1.
</p>
</dd>
<dt>&lsquo;<samp><var>r</var>c</samp>&rsquo;</dt>
<dd><p>Replace the lines in range <var>r</var> in the first file with the following
lines.  Like a combined add and delete, but more compact.  For example,
&lsquo;<samp>5,7c</samp>&rsquo; means change lines 5&ndash;7 of file 1 to read as the text file
2.
</p>
</dd>
<dt>&lsquo;<samp><var>r</var>d</samp>&rsquo;</dt>
<dd><p>Delete the lines in range <var>r</var> from the first file.  For example,
&lsquo;<samp>5,7d</samp>&rsquo; means delete lines 5&ndash;7 of file 1.
</p></dd>
</dl>

<hr>
<a name="Forward-ed"></a>
<div class="header">
<p>
Next: <a href="#RCS" accesskey="n" rel="next">RCS</a>, Previous: <a href="#ed-Scripts" accesskey="p" rel="prev">ed Scripts</a>, Up: <a href="#Scripts" accesskey="u" rel="up">Scripts</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Forward-ed-Scripts"></a>
<h4 class="subsection">2.5.2 Forward <code>ed</code> Scripts</h4>
<a name="index-forward-ed-script-output-format"></a>

<p><code>diff</code> can produce output that is like an <code>ed</code> script, but
with hunks in forward (front to back) order.  The format of the commands
is also changed slightly: command characters precede the lines they
modify, spaces separate line numbers in ranges, and no attempt is made
to disambiguate hunk lines consisting of a single period.  Like
<code>ed</code> format, forward <code>ed</code> format cannot represent incomplete
lines.
</p>
<p>Forward <code>ed</code> format is not very useful, because neither <code>ed</code>
nor <code>patch</code> can apply diffs in this format.  It exists mainly for
compatibility with older versions of <code>diff</code>.  Use the <samp>-f</samp> or
<samp>--forward-ed</samp> option to select it.
</p>
<hr>
<a name="RCS"></a>
<div class="header">
<p>
Previous: <a href="#Forward-ed" accesskey="p" rel="prev">Forward ed</a>, Up: <a href="#Scripts" accesskey="u" rel="up">Scripts</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="RCS-Scripts"></a>
<h4 class="subsection">2.5.3 <acronym>RCS</acronym> Scripts</h4>
<a name="index-RCS-script-output-format"></a>

<p>The <acronym>RCS</acronym> output format is designed specifically for use by
the Revision Control System, which is a set of free programs used for
organizing different versions and systems of files.  Use the
<samp>--rcs</samp> (<samp>-n</samp>) option to select this output format.  It
is like the forward <code>ed</code> format (see <a href="#Forward-ed">Forward ed</a>), but it
can represent arbitrary changes to the contents of a file because it
avoids the forward <code>ed</code> format&rsquo;s problems with lines
consisting of a single period and with incomplete lines.  Instead of
ending text sections with a line consisting of a single period, each
command specifies the number of lines it affects; a combination of the
&lsquo;<samp>a</samp>&rsquo; and &lsquo;<samp>d</samp>&rsquo; commands are used instead of &lsquo;<samp>c</samp>&rsquo;.  Also, if
the second file ends in a changed incomplete line, then the output
also ends in an incomplete line.
</p>
<p>Here is the output of &lsquo;<samp>diff -n lao tzu</samp>&rsquo; (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
</p>
<div class="example">
<pre class="example">d1 2
d4 1
a4 2
The named is the mother of all things.

a11 3
They both may be called deep and profound.
Deeper and more profound,
The door of all subtleties!
</pre></div>

<hr>
<a name="If_002dthen_002delse"></a>
<div class="header">
<p>
Previous: <a href="#Scripts" accesskey="p" rel="prev">Scripts</a>, Up: <a href="#Output-Formats" accesskey="u" rel="up">Output Formats</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Merging-Files-with-If_002dthen_002delse"></a>
<h3 class="section">2.6 Merging Files with If-then-else</h3>
<a name="index-merged-output-format"></a>
<a name="index-if_002dthen_002delse-output-format"></a>
<a name="index-C-if_002dthen_002delse-output-format"></a>
<a name="index-ifdef-output-format"></a>

<p>You can use <code>diff</code> to merge two files of C source code.  The output
of <code>diff</code> in this format contains all the lines of both files.
Lines common to both files are output just once; the differing parts are
separated by the C preprocessor directives <code>#ifdef <var>name</var></code> or
<code>#ifndef <var>name</var></code>, <code>#else</code>, and <code>#endif</code>.  When
compiling the output, you select which version to use by either defining
or leaving undefined the macro <var>name</var>.
</p>
<p>To merge two files, use <code>diff</code> with the <samp>-D <var>name</var></samp> or
<samp>--ifdef=<var>name</var></samp> option.  The argument <var>name</var> is the C
preprocessor identifier to use in the <code>#ifdef</code> and <code>#ifndef</code>
directives.
</p>
<p>For example, if you change an instance of <code>wait (&amp;s)</code> to
<code>waitpid (-1, &amp;s, 0)</code> and then merge the old and new files with
the <samp>--ifdef=HAVE_WAITPID</samp> option, then the affected part of your code
might look like this:
</p>
<div class="example">
<pre class="example">    do {
#ifndef HAVE_WAITPID
        if ((w = wait (&amp;s)) &lt; 0  &amp;&amp;  errno != EINTR)
#else /* HAVE_WAITPID */
        if ((w = waitpid (-1, &amp;s, 0)) &lt; 0  &amp;&amp;  errno != EINTR)
#endif /* HAVE_WAITPID */
            return w;
    } while (w != child);
</pre></div>

<p>You can specify formats for languages other than C by using line group
formats and line formats, as described in the next sections.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Line-Group-Formats" accesskey="1">Line Group Formats</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Formats for general if-then-else line groups.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Line-Formats" accesskey="2">Line Formats</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Formats for each line in a line group.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Example-If_002dthen_002delse" accesskey="3">Example If-then-else</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Sample if-then-else format output.
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Detailed-If_002dthen_002delse" accesskey="4">Detailed If-then-else</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A detailed description of if-then-else format.
</td></tr>
</table>

<hr>
<a name="Line-Group-Formats"></a>
<div class="header">
<p>
Next: <a href="#Line-Formats" accesskey="n" rel="next">Line Formats</a>, Up: <a href="#If_002dthen_002delse" accesskey="u" rel="up">If-then-else</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Line-Group-Formats-1"></a>
<h4 class="subsection">2.6.1 Line Group Formats</h4>
<a name="index-line-group-formats"></a>
<a name="index-formats-for-if_002dthen_002delse-line-groups"></a>

<p>Line group formats let you specify formats suitable for many
applications that allow if-then-else input, including programming
languages and text formatting languages.  A line group format specifies
the output format for a contiguous group of similar lines.
</p>
<p>For example, the following command compares the TeX files <samp>old</samp>
and <samp>new</samp>, and outputs a merged file in which old regions are
surrounded by &lsquo;<samp>\begin{em}</samp>&rsquo;-&lsquo;<samp>\end{em}</samp>&rsquo; lines, and new
regions are surrounded by &lsquo;<samp>\begin{bf}</samp>&rsquo;-&lsquo;<samp>\end{bf}</samp>&rsquo; lines.
</p>
<div class="example">
<pre class="example">diff \
   --old-group-format='\begin{em}
%&lt;\end{em}
' \
   --new-group-format='\begin{bf}
%&gt;\end{bf}
' \
   old new
</pre></div>

<p>The following command is equivalent to the above example, but it is a
little more verbose, because it spells out the default line group formats.
</p>
<div class="example">
<pre class="example">diff \
   --old-group-format='\begin{em}
%&lt;\end{em}
' \
   --new-group-format='\begin{bf}
%&gt;\end{bf}
' \
   --unchanged-group-format='%=' \
   --changed-group-format='\begin{em}
%&lt;\end{em}
\begin{bf}
%&gt;\end{bf}
' \
   old new
</pre></div>

<p>Here is a more advanced example, which outputs a diff listing with
headers containing line numbers in a &ldquo;plain English&rdquo; style.
</p>
<div class="example">
<pre class="example">diff \
   --unchanged-group-format='' \
   --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
%&lt;' \
   --new-group-format='-------- %dN line%(N=1?:s) added after %de:
%&gt;' \
   --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
%&lt;-------- to:
%&gt;' \
   old new
</pre></div>

<p>To specify a line group format, use <code>diff</code> with one of the options
listed below.  You can specify up to four line group formats, one for
each kind of line group.  You should quote <var>format</var>, because it
typically contains shell metacharacters.
</p>
<dl compact="compact">
<dt><samp>--old-group-format=<var>format</var></samp></dt>
<dd><p>These line groups are hunks containing only lines from the first file.
The default old group format is the same as the changed group format if
it is specified; otherwise it is a format that outputs the line group as-is.
</p>
</dd>
<dt><samp>--new-group-format=<var>format</var></samp></dt>
<dd><p>These line groups are hunks containing only lines from the second
file.  The default new group format is same as the changed group
format if it is specified; otherwise it is a format that outputs the
line group as-is.
</p>
</dd>
<dt><samp>--changed-group-format=<var>format</var></samp></dt>
<dd><p>These line groups are hunks containing lines from both files.  The
default changed group format is the concatenation of the old and new
group formats.
</p>
</dd>
<dt><samp>--unchanged-group-format=<var>format</var></samp></dt>
<dd><p>These line groups contain lines common to both files.  The default
unchanged group format is a format that outputs the line group as-is.
</p></dd>
</dl>

<p>In a line group format, ordinary characters represent themselves;
conversion specifications start with &lsquo;<samp>%</samp>&rsquo; and have one of the
following forms.
</p>
<dl compact="compact">
<dt>&lsquo;<samp>%&lt;</samp>&rsquo;</dt>
<dd><p>stands for the lines from the first file, including the trailing newline.
Each line is formatted according to the old line format (see <a href="#Line-Formats">Line Formats</a>).
</p>
</dd>
<dt>&lsquo;<samp>%&gt;</samp>&rsquo;</dt>
<dd><p>stands for the lines from the second file, including the trailing newline.
Each line is formatted according to the new line format.
</p>
</dd>
<dt>&lsquo;<samp>%=</samp>&rsquo;</dt>
<dd><p>stands for the lines common to both files, including the trailing newline.
Each line is formatted according to the unchanged line format.
</p>
</dd>
<dt>&lsquo;<samp>%%</samp>&rsquo;</dt>
<dd><p>stands for &lsquo;<samp>%</samp>&rsquo;.
</p>
</dd>
<dt>&lsquo;<samp>%c'<var>C</var>'</samp>&rsquo;</dt>
<dd><p>where <var>C</var> is a single character, stands for <var>C</var>.
<var>C</var> may not be a backslash or an apostrophe.
For example, &lsquo;<samp>%c':'</samp>&rsquo; stands for a colon, even inside
the then-part of an if-then-else format, which a colon would
normally terminate.
</p>
</dd>
<dt>&lsquo;<samp>%c'\<var>O</var>'</samp>&rsquo;</dt>
<dd><p>where <var>O</var> is a string of 1, 2, or 3 octal digits,
stands for the character with octal code <var>O</var>.
For example, &lsquo;<samp>%c'\0'</samp>&rsquo; stands for a null character.
</p>
</dd>
<dt>&lsquo;<samp><var>F</var><var>n</var></samp>&rsquo;</dt>
<dd><p>where <var>F</var> is a <code>printf</code> conversion specification and <var>n</var> is one
of the following letters, stands for <var>n</var>&rsquo;s value formatted with <var>F</var>.
</p>
<dl compact="compact">
<dt>&lsquo;<samp>e</samp>&rsquo;</dt>
<dd><p>The line number of the line just before the group in the old file.
</p>
</dd>
<dt>&lsquo;<samp>f</samp>&rsquo;</dt>
<dd><p>The line number of the first line in the group in the old file;
equals <var>e</var> + 1.
</p>
</dd>
<dt>&lsquo;<samp>l</samp>&rsquo;</dt>
<dd><p>The line number of the last line in the group in the old file.
</p>
</dd>
<dt>&lsquo;<samp>m</samp>&rsquo;</dt>
<dd><p>The line number of the line just after the group in the old file;
equals <var>l</var> + 1.
</p>
</dd>
<dt>&lsquo;<samp>n</samp>&rsquo;</dt>
<dd><p>The number of lines in the group in the old file; equals <var>l</var> - <var>f</var> + 1.
</p>
</dd>
<dt>&lsquo;<samp>E, F, L, M, N</samp>&rsquo;</dt>
<dd><p>Likewise, for lines in the new file.
</p>
</dd>
</dl>

<a name="index-LC_005fNUMERIC"></a>
<p>The <code>printf</code> conversion specification can be &lsquo;<samp>%d</samp>&rsquo;,
&lsquo;<samp>%o</samp>&rsquo;, &lsquo;<samp>%x</samp>&rsquo;, or &lsquo;<samp>%X</samp>&rsquo;, specifying decimal, octal,
lower case hexadecimal, or upper case hexadecimal output
respectively.  After the &lsquo;<samp>%</samp>&rsquo; the following options can appear in
sequence: a series of zero or more flags; an integer
specifying the minimum field width; and a period followed by an
optional integer specifying the minimum number of digits.
The flags are &lsquo;<samp>-</samp>&rsquo; for left-justification, &lsquo;<samp>'</samp>&rsquo; for separating
the digit into groups as specified by the <code>LC_NUMERIC</code> locale category,
and &lsquo;<samp>0</samp>&rsquo; for padding with zeros instead of spaces.
For example, &lsquo;<samp>%5dN</samp>&rsquo; prints the number of new lines in the group
in a field of width 5 characters, using the <code>printf</code> format <code>&quot;%5d&quot;</code>.
</p>
</dd>
<dt>&lsquo;<samp>(<var>A</var>=<var>B</var>?<var>T</var>:<var>E</var>)</samp>&rsquo;</dt>
<dd><p>If <var>A</var> equals <var>B</var> then <var>T</var> else <var>E</var>.
<var>A</var> and <var>B</var> are each either a decimal constant
or a single letter interpreted as above.
This format spec is equivalent to <var>T</var> if
<var>A</var>&rsquo;s value equals <var>B</var>&rsquo;s; otherwise it is equivalent to <var>E</var>.
</p>
<p>For example, &lsquo;<samp>%(N=0?no:%dN) line%(N=1?:s)</samp>&rsquo; is equivalent to
&lsquo;<samp>no lines</samp>&rsquo; if <var>N</var> (the number of lines in the group in the
new file) is 0, to &lsquo;<samp>1 line</samp>&rsquo; if <var>N</var> is 1, and to &lsquo;<samp>%dN lines</samp>&rsquo;
otherwise.
</p></dd>
</dl>

<hr>
<a name="Line-Formats"></a>
<div class="header">
<p>
Next: <a href="#Example-If_002dthen_002delse" accesskey="n" rel="next">Example If-then-else</a>, Previous: <a href="#Line-Group-Formats" accesskey="p" rel="prev">Line Group Formats</a>, Up: <a href="#If_002dthen_002delse" accesskey="u" rel="up">If-then-else</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Line-Formats-1"></a>
<h4 class="subsection">2.6.2 Line Formats</h4>
<a name="index-line-formats"></a>

<p>Line formats control how each line taken from an input file is
output as part of a line group in if-then-else format.
</p>
<p>For example, the following command outputs text with a one-character
change indicator to the left of the text.  The first character of output
is &lsquo;<samp>-</samp>&rsquo; for deleted lines, &lsquo;<samp>|</samp>&rsquo; for added lines, and a space for
unchanged lines.  The formats contain newline characters where newlines
are desired on output.
</p>
<div class="example">
<pre class="example">diff \
   --old-line-format='-%l
' \
   --new-line-format='|%l
' \
   --unchanged-line-format=' %l
' \
   old new
</pre></div>

<p>To specify a line format, use one of the following options.  You should
quote <var>format</var>, since it often contains shell metacharacters.
</p>
<dl compact="compact">
<dt><samp>--old-line-format=<var>format</var></samp></dt>
<dd><p>formats lines just from the first file.
</p>
</dd>
<dt><samp>--new-line-format=<var>format</var></samp></dt>
<dd><p>formats lines just from the second file.
</p>
</dd>
<dt><samp>--unchanged-line-format=<var>format</var></samp></dt>
<dd><p>formats lines common to both files.
</p>
</dd>
<dt><samp>--line-format=<var>format</var></samp></dt>
<dd><p>formats all lines; in effect, it sets all three above options simultaneously.
</p></dd>
</dl>

<p>In a line format, ordinary characters represent themselves;
conversion specifications start with &lsquo;<samp>%</samp>&rsquo; and have one of the
following forms.
</p>
<dl compact="compact">
<dt>&lsquo;<samp>%l</samp>&rsquo;</dt>
<dd><p>stands for the contents of the line, not counting its trailing
newline (if any).  This format ignores whether the line is incomplete;
See <a href="Incomplete-Lines.html#Incomplete-Lines">Incomplete Lines</a>.
</p>
</dd>
<dt>&lsquo;<samp>%L</samp>&rsquo;</dt>
<dd><p>stands for the contents of the line, including its trailing newline
(if any).  If a line is incomplete, this format preserves its
incompleteness.
</p>
</dd>
<dt>&lsquo;<samp>%%</samp>&rsquo;</dt>
<dd><p>stands for &lsquo;<samp>%</samp>&rsquo;.
</p>
</dd>
<dt>&lsquo;<samp>%c'<var>C</var>'</samp>&rsquo;</dt>
<dd><p>where <var>C</var> is a single character, stands for <var>C</var>.
<var>C</var> may not be a backslash or an apostrophe.
For example, &lsquo;<samp>%c':'</samp>&rsquo; stands for a colon.
</p>
</dd>
<dt>&lsquo;<samp>%c'\<var>O</var>'</samp>&rsquo;</dt>
<dd><p>where <var>O</var> is a string of 1, 2, or 3 octal digits,
stands for the character with octal code <var>O</var>.
For example, &lsquo;<samp>%c'\0'</samp>&rsquo; stands for a null character.
</p>
</dd>
<dt>&lsquo;<samp><var>F</var>n</samp>&rsquo;</dt>
<dd><p>where <var>F</var> is a <code>printf</code> conversion specification,
stands for the line number formatted with <var>F</var>.
For example, &lsquo;<samp>%.5dn</samp>&rsquo; prints the line number using the
<code>printf</code> format <code>&quot;%.5d&quot;</code>.  See <a href="#Line-Group-Formats">Line Group Formats</a>, for
more about printf conversion specifications.
</p>
</dd>
</dl>

<p>The default line format is &lsquo;<samp>%l</samp>&rsquo; followed by a newline character.
</p>
<p>If the input contains tab characters and it is important that they line
up on output, you should ensure that &lsquo;<samp>%l</samp>&rsquo; or &lsquo;<samp>%L</samp>&rsquo; in a line
format is just after a tab stop (e.g. by preceding &lsquo;<samp>%l</samp>&rsquo; or
&lsquo;<samp>%L</samp>&rsquo; with a tab character), or you should use the <samp>-t</samp> or
<samp>--expand-tabs</samp> option.
</p>
<p>Taken together, the line and line group formats let you specify many
different formats.  For example, the following command uses a format
similar to normal <code>diff</code> format.  You can tailor this command
to get fine control over <code>diff</code> output.
</p>
<div class="example">
<pre class="example">diff \
   --old-line-format='&lt; %l
' \
   --new-line-format='&gt; %l
' \
   --old-group-format='%df%(f=l?:,%dl)d%dE
%&lt;' \
   --new-group-format='%dea%dF%(F=L?:,%dL)
%&gt;' \
   --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
%&lt;---
%&gt;' \
   --unchanged-group-format='' \
   old new
</pre></div>

<hr>
<a name="Example-If_002dthen_002delse"></a>
<div class="header">
<p>
Next: <a href="#Detailed-If_002dthen_002delse" accesskey="n" rel="next">Detailed If-then-else</a>, Previous: <a href="#Line-Formats" accesskey="p" rel="prev">Line Formats</a>, Up: <a href="#If_002dthen_002delse" accesskey="u" rel="up">If-then-else</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="An-Example-of-If_002dthen_002delse-Format"></a>
<h4 class="subsection">2.6.3 An Example of If-then-else Format</h4>

<p>Here is the output of &lsquo;<samp>diff -DTWO lao tzu</samp>&rsquo; (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):
</p>
<div class="example">
<pre class="example">#ifndef TWO
The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
#endif /* ! TWO */
The Nameless is the origin of Heaven and Earth;
#ifndef TWO
The Named is the mother of all things.
#else /* TWO */
The named is the mother of all things.

#endif /* TWO */
Therefore let there always be non-being,
  so we may see their subtlety,
And let there always be being,
  so we may see their outcome.
The two are the same,
But after they are produced,
  they have different names.
#ifdef TWO
They both may be called deep and profound.
Deeper and more profound,
The door of all subtleties!
#endif /* TWO */
</pre></div>

<hr>
<a name="Detailed-If_002dthen_002delse"></a>
<div class="header">
<p>
Previous: <a href="#Example-If_002dthen_002delse" accesskey="p" rel="prev">Example If-then-else</a>, Up: <a href="#If_002dthen_002delse" accesskey="u" rel="up">If-then-else</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Detailed-Description-of-If_002dthen_002delse-Format"></a>
<h4 class="subsection">2.6.4 Detailed Description of If-then-else Format</h4>

<p>For lines common to both files, <code>diff</code> uses the unchanged line
group format.  For each hunk of differences in the merged output
format, if the hunk contains only lines from the first file,
<code>diff</code> uses the old line group format; if the hunk contains only
lines from the second file, <code>diff</code> uses the new group format;
otherwise, <code>diff</code> uses the changed group format.
</p>
<p>The old, new, and unchanged line formats specify the output format of
lines from the first file, lines from the second file, and lines common
to both files, respectively.
</p>
<p>The option <samp>--ifdef=<var>name</var></samp> is equivalent to
the following sequence of options using shell syntax:
</p>
<div class="example">
<pre class="example">--old-group-format='#ifndef <var>name</var>
%&lt;#endif /* ! <var>name</var> */
' \
--new-group-format='#ifdef <var>name</var>
%&gt;#endif /* <var>name</var> */
' \
--unchanged-group-format='%=' \
--changed-group-format='#ifndef <var>name</var>
%&lt;#else /* <var>name</var> */
%&gt;#endif /* <var>name</var> */
'
</pre></div>

<p>You should carefully check the <code>diff</code> output for proper nesting.
For example, when using the <samp>-D <var>name</var></samp> or
<samp>--ifdef=<var>name</var></samp> option, you should check that if the
differing lines contain any of the C preprocessor directives
&lsquo;<samp>#ifdef</samp>&rsquo;, &lsquo;<samp>#ifndef</samp>&rsquo;, &lsquo;<samp>#else</samp>&rsquo;, &lsquo;<samp>#elif</samp>&rsquo;, or
&lsquo;<samp>#endif</samp>&rsquo;, they are nested properly and match.  If they don&rsquo;t, you
must make corrections manually.  It is a good idea to carefully check
the resulting code anyway to make sure that it really does what you
want it to; depending on how the input files were produced, the output
might contain duplicate or otherwise incorrect code.
</p>
<p>The <code>patch</code> <samp>-D <var>name</var></samp> option behaves like
the <code>diff</code> <samp>-D <var>name</var></samp> option, except it operates on
a file and a diff to produce a merged file.  See <a href="Invoking-patch.html#patch-Options">patch Options</a>.
</p>
<hr>
<div class="header">
<p>
Previous: <a href="#Example-If_002dthen_002delse" accesskey="p" rel="prev">Example If-then-else</a>, Up: <a href="#If_002dthen_002delse" accesskey="u" rel="up">If-then-else</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>