[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[OT] Bash Script Help



This is not a debian specific question but I thought some of you could help. I am writing a shell script to parse a CSV file to prepare it for input into a program which will fit the data by a non-linear least squares fitting routine. This program takes input from a file containing two columns for "X" and "Y" data.

the CSV file looks like this:
Calibrations:
"X:", 0.0645, "Y:", 0.0645, "Units:", "um", "Gray Units:", ""
"Image Name", "Image Plane", "Elapsed Time", "Area", "Integrated Intensity"
"2005.05.16 - FRAPtest1.6", "1", "00:00.000", 774.838, 3.24557e+007
"2005.05.16 - FRAPtest1.6", "2", "00:02.510", 774.838, 3.23482e+007
"2005.05.16 - FRAPtest1.6", "3", "00:05.007", 774.838, 3.24578e+007
"2005.05.16 - FRAPtest1.6", "4", "00:07.507", 774.838, 2.77091e+007
"2005.05.16 - FRAPtest1.6", "5", "00:10.006", 774.838, 2.80516e+007
"2005.05.16 - FRAPtest1.6", "6", "00:12.507", 774.838, 2.82355e+007
"2005.05.16 - FRAPtest1.6", "7", "00:15.006", 774.838, 2.84682e+007
"2005.05.16 - FRAPtest1.6", "8", "00:17.506", 774.838, 2.86124e+007
"2005.05.16 - FRAPtest1.6", "9", "00:20.006", 774.838, 2.87942e+007
"2005.05.16 - FRAPtest1.6", "10", "00:22.507", 774.838, 2.89613e+007
"2005.05.16 - FRAPtest1.6", "11", "00:25.006", 774.838, 2.91049e+007
"2005.05.16 - FRAPtest1.6", "12", "00:27.506", 774.838, 2.9186e+007
"2005.05.16 - FRAPtest1.6", "13", "00:30.007", 774.838, 2.93118e+007
"2005.05.16 - FRAPtest1.6", "14", "00:32.507", 774.838, 2.94214e+007
"2005.05.16 - FRAPtest1.6", "15", "00:35.007", 774.838, 2.94967e+007
"2005.05.16 - FRAPtest1.6", "16", "00:37.507", 774.838, 2.96811e+007
---snip---

my script so far:
#!/bin/bash
tempfile=/dev/shm/frapfitter.$$
for INPUTFILE in "$@"
do
  # grab the info we need for frapfitter (filename and region areas)
  filename=$(awk -F '"' 'NR==4 {print $2}' "$INPUTFILE")
  sigarea=$(awk -F ", " 'NR==4 {print $4}' "$INPUTFILE")
  bgarea=$(awk -F ", " 'NR==54 {print $4}' "$INPUTFILE")

  # Parse the Metamorph output file and create an inputfile for
  # frapfitter
  {
      # remove calibration header
      sed -e '1,3d' "$INPUTFILE" |

      # grab "time" and "integrated intensity" columns
      cut -d "," -s -f 3,5 |

      # remove quotations, leading and trailing space, and ensure unix
      # format
      sed -e 's/"//g;s/^[ ^t]*//;s/[ ^t]*$//;' |
      dos2unix
      } > $tempfile
done

rm $tempfile

this creates a file that looks like this:
00:00.000, 3.24557e+007
00:02.510, 3.23482e+007
00:05.007, 3.24578e+007
00:07.507, 2.77091e+007
00:10.006, 2.80516e+007
00:12.507, 2.82355e+007
00:15.006, 2.84682e+007
00:17.506, 2.86124e+007
00:20.006, 2.87942e+007
00:22.507, 2.89613e+007
00:25.006, 2.91049e+007
00:27.506, 2.9186e+007
00:30.007, 2.93118e+007
00:32.507, 2.94214e+007
00:35.007, 2.94967e+007
00:37.507, 2.96811e+007
---snip---

I now need to covert the "elapse time" column from the string format "hours:min:sec" to a column containing just seconds. I am unsure how to do this. Can I use command substitution in a sed substitute command? (sed -e 's//$(command to do math)/') I don't necessarily need a piece of code but if someone could recommend a bash tool which is well suited for this task or outline some steps, I can probably get to my solution. Thanks in advance.



Reply to: