libgpiv so version 4: GpivFt. Show git hash (if available) in output and
[gpivtools.git] / src / misc / fi-keyline.pl
blob39e68ca20b46c813af00ea7523132ef74987bce6
1 #!/usr/bin/perl -w
3 # fi-keyline - Substracts parameters from an arbitrary file and writes them
4 # to gpivrc. Initially used for substarcting parameters from a
5 # README doc, containing description of experiments.
7 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
8 # Gerber van der Graaf <gerber_graaf@users.sourceforge.net
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
13 # any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software Foundation,
22 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #------------------------------------------------------------------
26 $VERSION = q$Id: fi-keyline.pl,v 1.4 2006-03-04 12:37:08 gerber Exp $;
27 $HELP = "Filters each line that starts with a keyword";
28 $USAGE = "gpiv_fi-keyline [-h|-help] [-p|-print] [-v|-version]
29 [-if|input_file] [-of|output_file] keyword
31 keys:
32 -h: on-line help
33 -p: prints process parameters/variables to stdout
34 -v: prints version
35 -if: input file
36 -of: output file
39 #[-n|-none]
40 #-n: suppresses real execution
41 #-p: prints process parameters/variables to stdout
44 #----------------- Command line arguments handling ----------
45 $opt_h = 0;
46 # $opt_n = 0;
47 $opt_p = 0;
48 $opt_v = 0;
50 use Getopt::Long;
51 GetOptions('h|help',
52 # 'n|none',
53 'p|print',
54 'v|version',
55 'if|input_file=s' => \$infile,
56 'of|output_file=s' => \$outfile,
59 if ($opt_h) {
60 print ("$HELP\n");
61 print ("$USAGE\n");
62 exit;
64 if ($opt_v) {
65 print ("$VERSION\n");
66 exit;
69 if ($#ARGV != 0) {
70 printf ("\nUsage: $USAGE\n");
71 exit;
74 $keyword = shift (@ARGV);
76 #-------------------------------------
77 if ($infile) {
78 if ($opt_p) {printf("input file = $infile\n");}
79 open (STDIN, "$infile") || die 'can\'t open $infile';
82 if ($outfile) {
83 if ($opt_p) {printf("output file = $outfile\n");}
84 open (STDOUT, ">$outfile") || die 'can\'t open $outfile';
91 while (<STDIN>) {
92 chomp;
93 if ($_ ne "" && (!/^(\#|;)/)) { #skip blank lines, # or ; signs at first col
95 s/^ *//; #removes eventually leading space
96 @words = split(/ /, $_); #splitting line $_ up in words
97 #same as @words = split
98 if ($words[0] =~ $keyword) {
99 shift @words;
100 if ($outfile) {
101 printf(STDOUT "@words\n");
102 } else {
103 printf("@words\n");
111 if ($infile) {close (STDIN) || die 'can\'t close $infile';}
112 if ($outfile) {close (STDOUT) || die 'can\'t close $infile';}
115 # Thats all folks