|
quote:
--------------------------------------------------------------------------------
if [ ! `cat formula.txt | cut -d ' ' -f 1 | grep "$code"` ];
--------------------------------------------------------------------------------
The code above uses the 'cat' command to pass the contents of the formula.txt file to the 'cut' command. The cut command is used to the cut out the first field ( this is the -f 1 portion of the command) within the file. Each field is delimited by 'cut' by a space (this is the -d ' ' portion of the command). Finally, the output of the cut command (that is, the first field) is passed to 'grep' which then attempts to match one of the entries in the file. Code is set to a value passed in by the user. This whole command sequence is surrounded by a file test which is testing whether or not 'grep' found a match. If it doesnt, the program exits and a message is printed to the screen. "No such formula"
quote:
--------------------------------------------------------------------------------
awk '$1 == "'"$code"'" { print '"$value"' * $2 }' formula.txt
--------------------------------------------------------------------------------
This peice of code searches for the entry in the formula.txt file that matches what the user typed in (I assume this is a value such as USD, or Pound, or Second etc). Awk will then match the entry and use the value (another peice of data entered by the user) multiplied by the second field ($2) of the record matched. The output of this step is printed to the screen.
A few thoughts, it would be better to use a "Select case" to generate a menu rather than have the user type in something that may not be in the file. Also, when using Awk, it would be more portable to use the built in -v switch to pass in shell variables to the program.
|