annotate tools/rdock/bin/sdmodify @ 2:0faa03a92843 draft default tip

Uploaded
author dzesikah
date Fri, 26 Aug 2016 10:19:49 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
1 #!/usr/bin/perl
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
2 # Script to set the first title line equal to a given data field
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
3 #
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
4 # Usage: sdmodify -f<DataField> [sdFiles]
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
5 #
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
6 # If sdFiles not given, reads from standard input
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
7 # Output is to standard output
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
8
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
9 use lib "$ENV{'RBT_ROOT'}/lib";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
10
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
11 use SDRecord;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
12
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
13 my $SDMODKEY = "ID";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
14
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
15 #Print help if no command line arguments
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
16 printHelpAndExit() if (scalar(@ARGV) == 0);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
17
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
18 #Parse command line arguments
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
19 my @files;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
20 while (scalar(@ARGV)) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
21 my $arg = shift @ARGV;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
22 printHelpAndExit() if ($arg eq '-h');
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
23 if (index($arg,'-f')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
24 $SDMODKEY = substr($arg,2);#modification key
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
25 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
26 else {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
27 push @files,$arg;#must be a filename
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
28 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
29 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
30 push @ARGV,@files;#put the filenames back in the arg list
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
31
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
32 #read records
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
33 my $sdRec = new SDRecord;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
34 my $nRec=0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
35 while ($sdRec->readRec('DATA'=>1,'LINES'=>1)) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
36 $sdRec->addData('_REC' => ++$nRec);#add record# as temp data field
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
37 #set the first line equal to the given data field
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
38 my $nLines = scalar (@{$sdRec->{'LINES'}});
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
39 if ($nLines > 0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
40 ${$sdRec->{'LINES'}}[0] = $sdRec->{'DATA'}->{$SDMODKEY};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
41 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
42 $sdRec->writeRec();
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
43 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
44
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
45 #!/usr/bin/perl
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
46 # Script to set the first title line equal to a given data field
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
47 #
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
48 # Usage: sdmodify -f<DataField> [sdFiles]
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
49 #
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
50 # If sdFiles not given, reads from standard input
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
51 # Output is to standard output
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
52
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
53 sub printHelpAndExit {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
54 print "\nScript to set the first title line equal to a given data field.\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
55 print "\nUsage:\tsdmodify -f<DataField> [sdFiles]\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
56 print "\n\tIf sdFiles not given, reads from standard input.\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
57 print "\n\tOutput is to standard output.\n\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
58 exit;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
59 }