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
|
\input texinfo @c -*-texinfo-*-
@c This file uses the @command command introduced in Texinfo 4.0.
@c %**start of header
@setfilename ffe.info
@settitle ffe - flat file extractor
@finalout
@c %**end of header
@include version.texi
@ifinfo
@dircategory Utilities
@direntry
* ffe: (ffe). Flat File Extractor.
@end direntry
@end ifinfo
@copying
This file documents version @value{VERSION} of @command{ffe}, a flat file extractor.
Copyright @copyright{} 2007 Timo Savinen
@quotation
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
@end quotation
@end copying
@titlepage
@title ffe
@subtitle flat file extractor
@subtitle Version @value{VERSION}, @value{UPDATED}
@author by Timo Savinen
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@c All the nodes can be updated using the EMACS command
@c texinfo-every-node-update, which is normally bound to C-c C-u C-e.
@ifnottex
@node Top, Overview, (dir), (dir)
@top ffe
@insertcopying
@end ifnottex
@c All the menus can be updated with the EMACS command
@c texinfo-all-menus-update, which is normally bound to C-c C-u C-a.
@menu
* Overview:: Preliminary information.
* Samples:: Samples using @command{ffe}.
* Invoking ffe:: How to run @command{ffe}.
* ffe configuration:: How @command{ffe} works.
* Problems:: Reporting bugs.
@end menu
@node Overview, Samples, Top, Top
@chapter Preliminary information
@cindex greetings
@cindex overview
The @command{ffe} program is a used to extract fields from flat files and to print them in different
formats. The input file structure and printing definitions are defined in a configuration file, which
is always required. Default configuration file is @file{~/.fferc} (@file{ffe.rc} in windows).
@command{ffe} is a command line tool developed for GNU/Linux and UNIX systems. @command{ffe} can read from
standard input and write to standard output, so it can be used as a part of a pipeline.
There is also binary distribution for windows.
@node Samples, Invoking ffe, Overview, Top
@chapter Samples using @command{ffe}
@cindex sample
One example of using @command{ffe} for printing personnel information in XML format from fixed length flat file:
@example
$ cat personnel
john Ripper 23
Scott Tiger 45
Mary Moore 41
$
@end example
@noindent
A file @file{personnel} contains three fixed length fields: @samp{FirstName}, @samp{LastName} and @samp{Age},
their respective lengths are 9,13 and 2.
@noindent
In order to print data above in XML, following configuration file must be available:
@example
$cat personnel.fferc
structure personel @{
type fixed
output xml
record person @{
field FirstName 9
field LastName 13
field Age 2
@}
@}
output xml @{
file_header "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
data "<%n>%t</%n>\n"
record_header "<%r>\n"
record_trailer "</%r>\n"
indent " "
@}
$
@end example
@noindent
Using ffe:
@example
$ffe -c personnel.fferc personnel
<?xml version="1.0" encoding="ISO-8859-1"?>
<person>
<FirstName>john</FirstName>
<LastName>Ripper</LastName>
<Age>23</Age>
</person>
<person>
<FirstName>Scott</FirstName>
<LastName>Tiger</LastName>
<Age>45</Age>
</person>
<person>
<FirstName>Mary</FirstName>
<LastName>Moore</LastName>
<Age>41</Age>
</person>
$
@end example
@node Invoking ffe, ffe configuration, Samples, Top
@chapter How to run @command{ffe}
@cindex running ffe
@cindex using
@command{ffe} is a command line tool. Normally @command{ffe} can be invoked as:
@code{ffe -o OUTPUTFILE INPUTFILE@dots{}}
@noindent
@command{ffe} uses the definitions from configuration file and tries to guess the input file
structure using the first 10 000 lines or 1 MB of input data.
@noindent
If the structure cannot be guessed the option @option{-s} must be used.
@menu
* Invocation:: Program invocation
* Configuration:: Input and printing definitions
* Guessing:: How ffe identifies input structure
* Limits:: Limitations
@end menu
@node Invocation, Configuration, , Invoking ffe
@section Program invocation
@cindex options
@noindent
The format for running the @command{ffe} program is:
@example
ffe @var{option} @dots{}
@end example
@noindent
@command{ffe} supports the following options:
@c Formatting copied from the Texinfo 4.0 manual.
@table @code
@item -c @var{file}
@itemx --configuration=@var{file}
Configuration is read from @var{file}, instead of @file{~/.fferc} (@file{ffe.rc} in windows).
@item -s @var{structure}
@itemx --structure=@var{structure}
Use structure @var{structure} for input file, suppresses guessing.
@item -p @var{output}
@itemx --print=@var{output}
Use output format @var{output} for printing. If not defined, then the record or structure related
output format is used. Printing can be suppressed using format @var{no}.
@item -o @var{file}
@itemx --output=@var{file}
Write output to @var{file} instead of standard output.
@item -f @var{list}
@itemx --field-list=@var{list}
Print only fields and constants expresses in comma separated list @var{list}. Order of names in
@var{list} defines also the printing order.
@item -e @var{expression}
@itemx --expression=@var{expression}
Print only those records for which the @var{expression} evaluates to true.
@item -a
@itemx --and
Expressions are combined with logical and, default is logical or.
@item -v
@itemx --invert-match
Print only those records which don't match the expression.
@item -l
@itemx --loose
Normally @command{ffe} stops when it encounters an input line which doesn't match any of
the records in selected structure. Defining this option causes @command{ffe} continue despite the error.
@item -r
@itemx --replace=@var{field}=@var{value}
Replace @var{field}s contents with @var{value} in output. @var{value} can contain same directives as output option @code{data}.
@item -?
@itemx --help
Print an informative help message describing the options and then exit
successfully.
@item -V
@itemx --version
Print the version number of @command{ffe} and then exit successfully.
@end table
All remaining options are names of input files, if no input files are specified or @code{-} is given, then the standard input is read.
@subheading Expressions (option @option{-e}, @option{--expression})
Expression can be used to select specific records comparing field values.
Expression has syntax @var{field}@strong{x}@var{value}, where @strong{x} is the comparison operator.
Expression is used to compare field's contents to @var{value} and if comparison is successful
the record is printed. Several expressions can be defined and at least one must evaluate to true in
order to print a record. If option @option{-a} is defined all expressions must evaluate to true.
@noindent
Expressions can be defined as:
@table @var
@item field@strong{=}value
Field @var{field} is equal to @var{value}.
@item field@strong{^}value
Field @var{field} starts with @var{value}.
@item field@strong{~}value
Field @var{field} contains @var{value}.
@item field@strong{!}value
Field @var{field} is not equal to @var{value}.
@item field@strong{?}value
Field @var{field} matches the regular expression @var{value}.
@command{ffe} supports POSIX extended regular expressions.
@end table
@node Configuration, Guessing, Invocation, Invoking ffe
@section Configuration
@cindex configuration
@command{ffe} uses a configuration file in order to read the input file and print the output.
Configuration file for @command{ffe} is a text file. The file may contain empty lines.
Commands are case sensitive. Comments begin with the @code{#}-character and end at the end of the line.
The @code{string} definitions can be enclosed in double quotation @code{"} characters.
@code{char} is a single character. @code{string} and @code{char} can contain following escape codes:
@code{\a}, @code{\b}, @code{\t}, @code{\n}, @code{\v}, @code{\f}, @code{\r}, @code{\"} and @code{\#}.
A backslash can be escaped as @code{\\}.
Configuration has two main parts: the structure, which defines the input file structure and
the output, which defines how the input data is formatted for output.
@subheading Common syntax
Common syntax for configuration file is:
@example
#comment
const @var{name} @var{value}
@dots{}
structure @var{name} @{
@i{option value} @dots{}
@dots{}
record @var{name} @{
@i{option value} @dots{}
@dots{}
@}
record @var{name} @{
@i{option value} @dots{}
@dots{}
@}
@dots{}
@}
structure @var{name} @{
@dots{}
@}
@dots{}
output @var{name} @{
@i{option value} @dots{}
@dots{}
@}
output @var{name} @{
@dots{}
@}
@dots{}
lookup @var{name} @{
@i{option value} @dots{}
@dots{}
@}
lookup @var{name} @{
@dots{}
@}
@dots{}
@end example
@subheading Structure
Keyword @code{structure} is used to define an input file content. An input file can contain several
types of records (or lines). E.g. file can have a header, data and trailer record types. Records
must be distinguishable from each other, this can be achieved defining different 'keys'
(@code{id} in record definition) or having different line lengths (for fixed length structure) or different count
of fields (for separated structure) for different records.
@noindent
Typically a @code{structure} maps to a file and a @code{records} maps to a line in the file.
@noindent
A structure is defined as:
@*
@example
structure @var{name} @{
@i{option value} @dots{}
@dots{}
@}
@end example
@noindent
A structure can contain following options:
@table @code
@item type fixed|separated [@var{char}] [*]
The fields in the input are fixed length fields or separated by @var{char}. If * is defined,
multiple sequential separators are considered as one. Default separator is comma.
@item quoted [@var{char}]
Fields may be quoted with char, default quotation mark is double quotation mark '"'.
A quotation mark is assumed be escaped as \@var{char} or doubling the mark as @var{charchar} in input.
Non escaped quotation marks are not preserved in output.
@item header first|all|no
Controls the occurrence of the header line. Default is no. If set as @emph{first} or @emph{all}, the first line
of the first input file is considered as header line containing the names of the fields. @emph{first}
means that only the first file has a header, @emph{all} means means that all files have a header,
all though the names are still taken from the header of the first file. Header line is handled
according the record definition, meaning that the name positions, separators etc. are the same as
for fields.
@item output @var{name}
All records belonging this structure are printed according output format name.
Default is to use output named as @samp{default}.
@item record @var{name} @{@i{options} @dots{}@}
Defines one record for a structure. A structure can contain several record types.
@end table
@subheading Record
A record defines one type of input line in a file. Different records can be distinguished using
the @code{id} option or different line lengths or field counts.
@noindent
A record is defined as:
@*
@example
record @var{name} @{
@i{option value} @dots{}
@dots{}
@}
@end example
@noindent
A record can contain following options:
@table @code
@item id @var{position} @var{string}
Identifies a record in the input file. Records are identified by the string in input record position
@var{position}. For fixed length input the position is the byte position of input record and for
separated input the position is the @var{position}'th field of the input record. Positions start from one.
A record definition can contain several id's, then all id's must match the input line
(@code{id}'s are @emph{and-ed}).
@item field @var{name}|FILLER|* [@var{length}]|* [@var{lookup}]
Defines one field in input structure. @var{length} is mandatory for fixed length input structure.
Length is also used for printing the fields in fixed length format (directive @code{%D} in output definitions).
If @emph{*} is defined instead of the name, then the @var{name} will be the ordinal number of the field,
or if the @code{header} option has value @emph{first} or @emph{all}, then the name of the field will taken from
the header line (first line of the input).
If field is named as @code{FILLER}, the field will not appear in output.
If @var{lookup} is defined the fields contents is used to make a lookup in lookup table @var{lookup}.
If @var{length} is not needed (separated format) but lookup is needed, use asterisk (*) in place of length definition.
The order of fields in configuration file is essential, it defines the field order in a record.
@item fields-from @var{record}
Fields for this record are the same as for record @var{record}. @code{field} and @code{fields-from} are mutually
exclusive.
@item output @var{name}
This record is printed according output format @var{name}. Default is to use output format defined in structure.
@end table
@subheading Output
Keyword @code{output} defines one output format for formatting the flat file data. Formatting
is controlled using options and printf style directives. An output definition is all ways independent
from structure, so one output format can be used with different input file formats.
@noindent
A output is defined as:
@*
@example
output @var{name} @{
@i{option value} @dots{}
@dots{}
@}
@end example
@noindent
Actual formatting and printing is controlled using @emph{pictures} in output options. Pictures can contain
following printf style directives:
@table @code
@item %f
Name of the input file.
@item %s
Name of the current structure.
@item %r
Name of the current record.
@item %o
Input record number in current file.
@item %O
Input record number starting from the first file.
@item %n
Field name.
@item %t
Field contents, without leading and trailing whitespaces.
@item %d
Field contents.
@item %D
Field contents, right padded to the field length (requires length definition for the field).
@item %l
Lookup value which has been found using current field as a search key.
@item %L
Lookup value, right padded to the field length.
@item %p
Fields start position in a record. For fixed structure this is field's byte position in the input line
and for separated structure this is the ordinal number of the field. Starts from one.
@item %e
Does not print anything, causes still the "field empty" check to be performed.
Can be used when only the names of non-empty fields should be printed.
@item %%
Percent sign.
@end table
@noindent
Output options:
@table @code
@item file_header @var{picture}
@var{picture} is printed once before file contents.
@item file_trailer @var{picture}
@var{picture} is printed once after file contents.
@item header @var{picture}
If defined, then the header line describing the field names is printed before records.
Every field name is printed according the @var{picture} using the same separator and fields length as
defined for the fields. Picture can contain only @code{%n} directive.
@item data @var{picture}
Field contents is printed according @var{picture}.
@item lookup @var{picture}
If current field is related to lookup table, then this @var{picture} is used instead of picture from @code{data}.
This makes possible to use different picture when the field is related to a lookup table. Default is to use the picture from @code{data}.
@item separator @var{string}
All fields are terminated by @var{string}, except the last field of the record.
Default is not to print separator.
@item record_header @var{picture}
All records are started by @var{picture}. Default is not to print the record header.
@item record_trailer @var{picture}
All records are ended with @var{picture}. Default is newline.
@item justify left|right|@var{char}
The output from the @code{data} option is left or right justified.
@var{char} justifies output according the first occurrence of @var{char}
in the data picture. Default is left.
@item indent @var{string}
Record contents is intended by @var{string}.
Field contents is intended by two times the string. Default is not to indent.
@item field-list @var{name1},@var{name2},@dots{}
Only fields and constants named as @var{name1},@var{name2},@dots{} are printed, same effect as has option @option{-f}.
Default is print all fields and no constants. Fields and constants are also printed in the same order as they are listed.
@item no-data-print yes|no
If @code{field-list} is defined and and this is set as no and none of the fields in @code{field-list}
does not belong to the current record, then the @code{record_header} and @code{record_trailer} are not printed.
Default is yes.
@item field-empty-print yes|no
When set as no, nothing is printed for fields which consist entirely of characters from @code{empty-chars}.
If none of the fields of a record are printed, then the printing of @code{record_trailer} is also suppressed.
Default is yes.
@item empty-chars @var{string}
@var{string} defines a set of characters which define an "empty" field. Default is
@w{" \f\n\r\t\v"} (space, form-feed, newline, carriage return, horizontal tab and vertical tab).
@end table
@subheading Lookup
Keyword @code{lookup} defines a lookup table which can searched using field contents. Found values can
be printed using output directives @code{%l} and @code{%L}.
@noindent
A lookup table is defined as:
@*
@example
lookup @var{name} @{
@i{option value} @dots{}
@dots{}
@}
@end example
@noindent
Lookup options:
@table @code
@item search exact | longest
Search method for this table. Either exact or longest match is used when searching the table. Default is @code{exact}.
@item pair @var{key} @var{value}
Defines one key/value pair for the lookup table.
@item file @var{name} [@var{separator}]
Data for the lookup table is read from file @var{name}. Each line in file @var{name} is considered as a key/value pair
separated by a single character @var{separator}. Default separator is semicolon. Lines without separator are silently omitted.
@strong{Note}: File size is limited by available memory because the file contents is loaded to memory.
@item default-value @var{value}
If searching the lookup table is unsuccessful then @var{value} is used in printing. Default is empty string.
@end table
@subheading Constants
Keyword @code{const} defines one name/value pair which can be used as an additional output field.
Constants can be used only in field lists (option @option{-f,--field-list}, or output option @code{field-list}).
Constants can be used to add fields to output which do not appear in input. E.g. new fields for
separated output or adding spaces after a fixed length field (changing the field length).
Note that @var{value} is printed as it is for every record. It cannot be changed record by record.
If a constant has the same name as one of the input fields, the value @var{value} is printed instead of
the input field contents.
A constant is defined as:
@*
@example
const @var{name} @var{value}
@end example
When @var{name} appears in field list it is treated as one of the input fields having contents @var{value}.
@node Guessing,Limits,Configuration,Invoking ffe
@section Guessing
@cindex guess
If @option{-s} is not given, @command{ffe} tries to guess the input structure.
@command{ffe} reads first 10 000 lines or 1 MB of input data and tries to match the structure definitions
from configuration file to input stream. If all lines match one and only one structure, the structure is used
for reading the input file.
@noindent
Guessing uses following execution cycle:
@enumerate
@item
Input line is read
@item
All record @code{id}'s are compared to the input line, if all @code{id}'s of a record match
the input line and the
records line length matches the total length (or total count for separated structure) of the fields,
the record is considered to match the input line. If there are no @code{id}'s,
only the line length or field count is checked.
@item
If all lines match at least one of the records in a particular structure, the structure is considered as selected.
There must be only one structure matching all lines used for guessing.
@end enumerate
@node Limits, , Guessing, Invoking ffe
@section Limitations
@cindex big files
@cindex limits
At least in GNU/Linux @command{ffe} should be able to handle big files (> 4 GB), other
systems are not tested.
Regular expression can be used in expressions (operator @strong{?} in option @option{-e}, @option{--expression}) only in systems where
regular expression functions (regcomp, regexec, @dots{}) are available.
@node ffe configuration, Problems, Invoking ffe, Top
@chapter How @command{ffe} works
Following examples use two different input files:
@subheading Fixed length example
Fixed length personnel file with header and trailer, line (record) is identified by the
first byte (H = Header, E = Employee, B = Boss, T = trailer).
@example
$cat personnel.fix
H2006-02-25
EJohn Ripper 23
BScott Tiger 45
EMary Moore 41
ERidge Forrester 31
T0004
$
@end example
@noindent
Structure for reading file above. Note that record @samp{boss} reuses fields from @samp{employee}.
@example
structure personel_fix @{
type fixed
record header @{
id 1 H
field type 1
field date 10
@}
record employee @{
id 1 E
field EmpType 1
field FirstName 9
field LastName 13
field Age 2
@}
record boss @{
id 1 B
fields-from employee
@}
record trailer @{
id 1 T
field type 1
field count 4
@}
@}
@end example
@subheading Separated example
Same file as above, but now separated by colon.
@example
$cat personnel.sep
H,2006-02-25
E,john,Ripper,23
B,Scott,Tiger,45
E,Mary,Moore,41
E,Ridge,Forrester,31
T,0004
$
@end example
@noindent
Structure for reading file above. Note that the field lengths are not needed in separated format.
@example
structure personel_sep @{
type separated ,
record header @{
id 1 H
field type
field date
@}
record employee @{
id 1 E
field type
field FirstName
field LastName
field Age
@}
record boss @{
id 1 B
fields-from employee
@}
record trailer @{
id 1 T
field type
field count
@}
@}
@end example
@subheading Printing in XML format
Data in examples above can be printed in XML using output definition like:
@example
output xml @{
file_header "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
data "<%n>%t</%n>\n"
record_header "<%r>\n"
record_trailer "</%r>\n"
indent " "
@}
@end example
@noindent
Example output using command (assuming definitions above are saved in ~/.fferc)
@code{ffe -p xml personnel.sep}
@example
<?xml version="1.0" encoding="UTF-8"?>
<header>
<type>H</type>
<date>2006-02-25</date>
</header>
<employee>
<type>E</type>
<FirstName>john</FirstName>
<LastName>Ripper</LastName>
<Age>23</Age>
</employee>
<boss>
<type>B</type>
<FirstName>Scott</FirstName>
<LastName>Tiger</LastName>
<Age>45</Age>
</boss>
<employee>
<type>E</type>
<FirstName>Mary</FirstName>
<LastName>Moore</LastName>
<Age>41</Age>
</employee>
<employee>
<type>E</type>
<FirstName>Ridge</FirstName>
<LastName>Forrester</LastName>
<Age>31</Age>
</employee>
<trailer>
<type>T</type>
<count>0004</count>
</trailer>
@end example
@subheading Printing sql commands
Data in examples above can be loaded to database by generated sql commands. Note that the header and trailer
are not loaded, because only fields @samp{FirstName},@samp{LastName} and @samp{Age} are printed and @samp{no-data-print}
is set as no. This prevents the @samp{record_header} and @samp{record_trailer} to be printed for file header and trailer.
@example
output sql @{
file_header "delete table boss;\ndelete table employee;\n"
record_header "insert into %r values("
data "'%t'"
separator ","
record_trailer ");\n"
file_trailer "commit\nquit\n"
no-data-print no
field-list FirstName,LastName,Age
@}
@end example
@noindent
Output from command
@code{ffe -p sql personnel.sep}
@example
delete table boss;
delete table employee;
insert into employee values('john','Ripper','23');
insert into boss values('Scott','Tiger','45');
insert into employee values('Mary','Moore','41');
insert into employee values('Ridge','Forrester','31');
commit
quit
@end example
@subheading Human readable output
This output format shows the fields suitable for displaying in screen or printing.
@example
output nice @{
record_header "%s - %r - %f - %o\n"
data "%n=%t\n"
justify =
indent " "
@}
@end example
@noindent
Output from command
@code{ffe -p nice personnel.fix}
@example
personel - header - personnel.fix - 1
type=H
date=2006-02-25
personel - employee - personnel.fix - 2
EmpType=E
FirstName=John
LastName=Ripper
Age=23
personel - boss - personnel.fix - 3
EmpType=B
FirstName=Scott
LastName=Tiger
Age=45
personel - employee - personnel.fix - 4
EmpType=E
FirstName=Mary
LastName=Moore
Age=41
personel - employee - personnel.fix - 5
EmpType=E
FirstName=Ridge
LastName=Forrester
Age=31
personel - trailer - personnel.fix - 6
type=T
count=0004
@end example
@subheading HTML table
Personnel data can be displayed as HTML table using output like:
@example
output html @{
file_header "<html>\n<head>\n</head>\n<body>\n<table border=\"1\">\n<tr>\n"
header "<th>%n</th>\n"
record_header "<tr>\n"
data "<td>%t</td>\n"
file_trailer "</table>\n</body>\n</html>\n"
no-data-print no
@}
@end example
@noindent
Output from command
@code{ffe -p html -f FirstName,LastName,Age personnel.fix}
@example
<html>
<head>
</head>
<body>
<table border="1">
<tr>
<th>FirstName</th>
<th>LastName</th>
<th>Age</th>
<tr>
<td>John</td>
<td>Ripper</td>
<td>23</td>
<tr>
<td>Scott</td>
<td>Tiger</td>
<td>45</td>
<tr>
<td>Mary</td>
<td>Moore</td>
<td>41</td>
<tr>
<td>Ridge</td>
<td>Forrester</td>
<td>31</td>
</table>
</body>
</html>
@end example
@subheading Using expression
Printing only Scott's record using expression with previous example:
@code{ffe -p html -f FirstName,LastName,Age -e FirstName^Scott personnel.fix}
@example
<html>
<head>
</head>
<body>
<table border="1">
<tr>
<th>FirstName</th>
<th>LastName</th>
<th>Age</th>
<tr>
<td>Scott</td>
<td>Tiger</td>
<td>45</td>
</table>
</body>
</html>
@end example
@subheading Using replace
Make all bosses and write a new personnel file printing the fields in fixed length format
using directive @code{%D}:
@noindent
Output definition:
@example
output fixed
@{
data "%D"
@}
@end example
@noindent
Write a new file:
@example
$ffe -p fixed -r EmpType=B -o personnel.fix.new personnel.fix
$cat personnel.fix.new
H2006-02-25
BJohn Ripper 23
BScott Tiger 45
BMary Moore 41
BRidge Forrester 31
T0004
$
@end example
@subheading Using constant
The length of the fields FirstName and LastName in fixed length format will be made two bytes longer.
This will be done by printing a constant after those two fields.
We use dots instead of spaces in order to make change more visible.
Because we do not want to change header and trailer we need specially crafted configuration file.
Employee and boss records will be printed using new output @var{fixed2} and other records will be printed using
output @var{default}.
New definition file @file{new_fixed.rc}:
@example
const 2dots ".."
structure personel_fix @{
type fixed
record header @{
id 1 H
field type 1
field date 10
@}
record employee @{
id 1 E
field EmpType 1
field FirstName 9
field LastName 13
field Age 2
output fixed2
@}
record boss @{
id 1 B
fields-from employee
output fixed2
@}
record trailer @{
id 1 T
field type 1
field count 4
@}
@}
output default
@{
data "%D"
@}
output fixed2
@{
data "%D"
field-list Emptype,FirstName,2dots,LastName,2dots,Age
@}
@end example
@noindent
Print new flat file:
@example
$ ffe -c new_fixed.rc personel_fix
H2006-02-25
EJohn ..Ripper ..23
BScott ..Tiger ..45
EMary ..Moore ..41
ERidge ..Forrester ..31
T0004
$
@end example
@subheading Using lookup table
Lookup table is used to explain the EmpTypes contents in output format @code{nice}:
@noindent
Lookup definition:
@example
lookup Type
@{
search exact
pair H Header
pair B "He is a Boss!"
pair E "Not a Boss!"
pair T Trailer
default-value "Unknown record type!"
@}
@end example
@noindent
Mapping the EmpType field to lookup:
@example
structure personel_fix @{
type fixed
record header @{
id 1 H
field type 1
field date 10
@}
record employee @{
id 1 E
field EmpType 1 Type
field FirstName 9
field LastName 13
field Age 2
@}
record boss @{
id 1 B
fields-from employee
@}
record trailer @{
id 1 T
field type 1
field count 4
@}
@}
@end example
@noindent
Adding the lookup option to output definition @code{nice}.
@example
output nice @{
record_header "%s - %r - %f - %o\n"
data "%n=%t\n"
lookup "%n=%t (%l)\n"
justify =
indent " "
@}
@end example
@noindent
Running ffe:
@example
$ffe -p nice personnel.fix
personel_fix - header - personel_fix - 1
type=H
date=2006-02-25
personel_fix - employee - personel_fix - 2
EmpType=E (Not a Boss!)
FirstName=John
LastName=Ripper
Age=23
personel_fix - boss - personel_fix - 3
EmpType=B (He is a Boss!)
FirstName=Scott
LastName=Tiger
Age=45
personel_fix - employee - personel_fix - 4
EmpType=E (Not a Boss!)
FirstName=Mary
LastName=Moore
Age=41
personel_fix - employee - personel_fix - 5
EmpType=E (Not a Boss!)
FirstName=Ridge
LastName=Forrester
Age=31
personel_fix - trailer - personel_fix - 6
type=T
count=0004
@end example
@subheading External lookup file
In previous example the lookup data could be read from external file like:
@example
$cat lookupdata
H;Header
B;He is a Boss!
E;Not a Boss!
T;Trailer
$
@end example
@noindent
Lookup definition using file above:
@example
lookup Type
@{
search exact
file lookupdata
default-value "Unknown record type!"
@}
@end example
@subheading The whole configuration file used in examples
@example
structure personel_fix @{
type fixed
record header @{
id 1 H
field type 1
field date 10
@}
record employee @{
id 1 E
field EmpType 1 Type
field FirstName 9
field LastName 13
field Age 2
@}
record boss @{
id 1 B
fields-from employee
@}
record trailer @{
id 1 T
field type 1
field count 4
@}
@}
structure personel_sep @{
type separated ,
record header @{
id 1 H
field type
field date
@}
record employee @{
id 1 E
field type
field FirstName
field LastName
field Age
@}
record boss @{
id 1 B
fields-from employee
@}
record trailer @{
id 1 T
field type
field count
@}
@}
output xml @{
file_header "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
data "<%n>%t</%n>\n"
record_header "<%r>\n"
record_trailer "</%r>\n"
indent " "
@}
output sql @{
file_header "delete table boss;\ndelete table employee;\n"
record_header "insert into %r values("
data "'%t'"
separator ","
record_trailer ");\n"
file_trailer "commit\nquit\n"
no-data-print no
field-list FirstName,LastName,Age
@}
output nice @{
record_header "%s - %r - %f - %o\n"
data "%n=%t\n"
lookup "%n=%t (%l)\n"
justify =
indent " "
@}
output html @{
file_header "<html>\n<head>\n</head>\n<body>\n<table border=\"1\">\n<tr>\n"
header "<th>%n</th>\n"
record_header "<tr>\n"
data "<td>%t</td>\n"
file_trailer "</table>\n</body>\n</html>\n"
no-data-print no
@}
output fixed
@{
data "%D"
@}
lookup Type
@{
search exact
pair H Header
pair B "He is a Boss!"
pair E "Not a Boss!"
pair T Trailer
default-value "Unknown record type!"
@}
@end example
@subheading Using @command{ffe} to test file integrity
@command{ffe} can be used to check flat file integrity, because @command{ffe}
checks for all lines the line length and id's for fixed length structure
and field count and id's for separated structure.
@noindent
Integrity can be checked using command
@code{ffe -p no -l inputfiles@dots{}}
@noindent
Because option @option{-p} has value @code{no} nothing is printed to output except the error messages.
Option @option{-l} causes all erroneous lines to be reported, not just the first one.
@noindent
Example output:
@example
ffe: Invalid input line in file 'inputfileB', line 14550
ffe: Invalid input line in file 'inputfileD', line 12
@end example
@node Problems, , ffe configuration, Top
@chapter Reporting Bugs
@cindex bugs
@cindex problems
If you find a bug in @command{ffe}, please send electronic mail to
@email{tjsa@@iki.fi}. Include the version number, which you can find by
running @w{@samp{ffe --version}}. Also include in your message the
output that the program produced and the output you expected.@refill
If you have other questions, comments or suggestions about
@command{ffe}, contact the author via electronic mail to
@email{tjsa@@iki.fi}. The author will try to help you out, although he
may not have time to fix your problems.
@contents
@bye
|