0
|
1 #!/usr/bin/perl
|
|
2 # add extra fields to SD records
|
|
3 use lib "$ENV{'RBT_ROOT'}/lib";
|
|
4 use SDRecord;
|
|
5
|
|
6 printHelpAndExit() if (scalar(@ARGV) == 0);
|
|
7 #Parse command line arguments
|
|
8 my @files;
|
|
9 my $arg = shift @ARGV;
|
|
10 printHelpAndExit() if ($arg eq '-h');
|
|
11 #read records
|
|
12 my $sdRec = new SDRecord;
|
|
13 my $nRec=0;
|
|
14 # if not -h, then must be the FieldName
|
|
15 my $FieldName = $arg;
|
|
16 my $FieldVal = shift @ARGV; # and this must be the filed value
|
|
17 # rest are the filenames
|
|
18 while ($sdRec->readRec('DATA'=>1,'LINES'=>1)) {
|
|
19 $sdRec->addData('_REC' => ++$nRec);#add record# as temp data field
|
|
20 $sdRec->addData('_FILE' => $ARGV);#add filename as temp data field
|
|
21 $sdRec->addDataAndLines($FieldName => $FieldVal);
|
|
22 $sdRec->writeRec();#write record
|
|
23 }
|
|
24
|
|
25 sub printHelpAndExit {
|
|
26 print "\nAdding fields to SD files\n";
|
|
27 print "Usage:\n";
|
|
28 print "\tsdfield <Fieldname> <value> <infile[s]>\n";
|
|
29 print "\t-h\tthis help\n";
|
|
30 print "\t\n";
|
|
31 }
|