www.Michael-Forman.com

massage>>  Click to open

Name massage
Version 1.4
Updated 2003/03/16 22:40:17
RCS massage,v 1.4 2003/03/16 22:40:17 forman Exp forman
Rating star star star star no star
Category Math, File manipulation
Description massage performs simple algebraic operations on columnar textual data. It is useful for scaling or offsetting rows of data before plotting. The user supplies a single operator followed by a list of numeric modifiers. The operator applies the numeric modifiers to their corresponding columns and prints out the result. It allows for the quick modification of text files holding data without the overhead of reading files into Matlab. It is designed to operate well with files containing text, either ignoring the text where needed or operating on numbers imbedded in the text.

Download massage

Title
forman:1> cat data.txt
 0    0   0
10  100   5
20  400  20
30  900  45
40 1600  80
50 2500 125

forman:2> massage / . 2 . + . . 5 < data.txt > new.txt

forman:3> cat new.txt
 0    0   5
10   50  10
20  200  25
30  450  50
40  800  85
50 1250 130
Scroll
MASSAGE(1)     User Contributed Perl Documentation     MASSAGE(1)



NAME
       massage - perform calculations on columnar textual data

SYNOPSIS
       massage [ -dhsvw ] [ -f file ] ([COND]) [OP] [MOD]

DESCRIPTION
       massage performs simple algebraic operations on columnar
       textual data.  It is useful for scaling or offsetting rows
       of data before plotting.  The user supplies a single oper­
       ator followed by a list of numeric modifiers.  The opera­
       tor applies the numeric modifiers to their corresponding
       columns and prints out the result.  It allows for the
       quick modification of text files holding data without the
       overhead of reading files into Matlab.  It is designed to
       operate well with files containing text, either ignoring
       the text where needed or operating on numbers imbedded in
       the text.

OPTIONS
       -d --debug

       Enables verbose debugging code.

       -f --file [filename]

       Allows the filename to be specified on the command line.

       -h --help

       Prints this information.

       -s --strict

       Stops sanity checking of numbers and operator-number
       pairs.  Using the "--strict" option will disable autocom­
       pletion of omitted numbers and allow divide-by-zero
       errors.  It should only be used in conjunction with debug­
       ging.

       -v --verbose

       Prints lines of the text file, which contain strings and
       are thus not operated on.

       -w --words

       Default behavior is to ignore and pass lines that contain
       non-numeric characters.  If the "--text" flag is present,
       lines containing words will be operated upon, with words
       passed through and numbers between the words operated
       upon.  Useful for converting a file such as this:

         day 1: 184 lbs
         day 2: 182 lbs

       to this

         day 1: 83.636 kg
         day 2: 82.727 kg

       using "massage / 1 1 2.2 | "sed 's/lbs/kg/'".

CONDITIONS
       Conditions are optionally specified as the first command-
       line parameter.  If the condition is omitted or the condi­
       tion is present and true, the operator and modifer are
       applied.  If the condition is present and false the opera­
       tion will be skipped, passing the data through unmodified.

       The following are examples of valid conditions:

         ">5"          greater than 5

         "<=0"         less than or equal to zero

         ==17          equal to 17

         "(>5)&&(<10)" greater than 5 and less than 10

         "(<5)||(>10)" less than 5 or greater than 10

       It is necessary to quote the conditons to prevent the
       shell from interpreting the ">" and "<" characters as
       redirections for STDIN and STDOUT.

OPERATORS
       + -

       Addition and subtraction.

       * x /

       Multiplication and division.  Both the "*" and "x" charac­
       ters work for multiplication.

       ^ **

       Raise to a power.  Both the "^" and "**" characters work
       for power.

       =

       Set to a specified value.

MODIFIERS
       Modifiers are always numbers with the exception of:

       . NOP

       The "NOP" modifer always leaves the data in a column
       unmodified regardless of the specified operator or condi­
       tion.  Both the keyword "NOP" and the character "."  can
       be used to specify no operation.

       If modifiers are omitted, they are assigned the value
       "NOP" by default.

ADVANCED USAGE
       Advanced usage allows an arbitray number of conditions,
       operators, and modifiers to specified on the command line.
       Each group follows the other in series:

       massage [cn 1] [op 1] [mod 1] [cn 2] [op 2] [mod 2] ...

       The two following commands, the first with simple usage
       and the second with advanced usage, will have the same
       functionality:

       cat file.in | massage <0 = 0 | massage ==0 + 10 > file.out

       massage <0 = 0 ==0 + 10 < file.in > file.out

       Advanced usage is more compact but is less readable.  Go
       on, be the guru.

EXAMPLE
       The following three examples below will divide the first
       column of "file.in" by 60, the second column by 10, and
       leave the remaing columns uneffected.  Omitted modifiers
       are automatically set to a value ("NOP") that will not
       affect the original column value based on the supplied
       operator.

       massage / 60 10 1 1 1  < file.in > file.out

       massage / 60 10 . . . < file.in > file.out

       massage / 60 10 < file.in > file.out

       The example below adds 10 to the first column, and sub­
       tracts 14 from the second.  The file name may also be sup­
       plied as an argument using the "--file" flag.

       massage + 10 0 -14 -f file.in > file.out

       The example below sets the value in the third column to
       zero if a value in that column is less than zero.

       massage "<0" = . . 0 < file.in > file.out

       The examples below highlight how lines with text can
       either be ignored or descended into and operated upon
       using the "-w" flag.  The first example prints "U R No 1".
       The second prints "U R No 10".

       echo "U R No 1" | massage    + . . . 9

       echo "U R No 1" | massage -w + . . . 9

       The example below shows an advanced usage with two sets of
       conditions, operators, and modifiers.  The result is that
       the third column will have 30 added to it and be set to
       zero if it's less than zero.

       massage + . . 30  <0 = . . 0 < file.in > file.out

BUGS
       Currently the program lacks the ability to automatically
       retort, "No this shouldn't be done in Matlab".

SEE ALSO
       massage message-classic

AUTHOR AND COPYRIGHT
        Michael Forman  http://www.Michael-Forman.com

        Copyright (C) 2001, 2002 Michael Forman.  All rights reserved.
        This program is free software; you can redistribute it
        and/or modify it under the same terms as Perl itself.
        Please see the Perl Artistic License.

VERSION

        Current Revision:  $Revision: 1.4 $
        Last Modification: $Date: 2003/03/16 22:40:17 $



perl v5.8.1                 2004-03-16                 MASSAGE(1)




Copyright © 2008 Michael Forman