Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Takes data to be processed as an input file, outputting data to stdout (the terminal)
- input_data="$1"
- lookup_file="materials.txt"
- while IFS= read -r input_line; do
- materialdimension1="$(echo ${input_line} | awk '{print $1}')"
- material="${materialdimension1%%[0-9]*}" # Strips all characters from the line starting from the first digit
- #material="${input_line:0:3}" We can use this line instead if every material has a length of 3 characters, and is always the first entry in the line
- dimension1="${materialdimension1##*[a-zA-Z]}" # Strips all characters ahead of the last letter
- # dimension1="${materialdimension1:3}" We can use this line instead if, as above, every material has length 3
- dimensions2x3="$(echo ${input_line} | awk '{print $2}')"
- dimension2="${dimensions2x3%%x*}" # Strips all characters trailing an 'x'
- dimension3="${dimensions2x3##*x}" # Strips all characters preceeding an 'x'
- amount="$(echo ${input_line} | awk '{print $3}' | sed 's/x//')" # Strips trailing 'x' from amount value
- volumecost="$(grep "${material}" "${lookup_file}" | awk '{print $2}')" # Pulls cost/volume value from the lookup file for the current material
- total=$(( (dimension1 * dimension2 * dimension3 * amount * volumecost ) / 1000000 )) # Multiply everything together, divide by 1,000,000
- echo "${total} - ${input_line}" # Output the value, along with the input line (for demonstration purposes)
- done < "${input_data}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement