I have a data file formatted as in the following line:
Achadd 0:35 1:35 2:35 3:40 4:40 5:40
I need the minutes converted to seconds; I wrote a script, min2sec, to do so for one datapoint. I was hoping to use sed as in the following code to call this script and reformat the line:
cat datafile.txt | sed 's/\([0-9]*:[0-9]*\)/ $((min2sec \1))/g'
Unfortunately, sed is not calling min2sec. Does anyone have any pointers? I have little experience with sed.
Thanks for the reply. (Where's the "duh!" emoticon when I need one?)
There is still a problem, however.
cat datafile.txt | sed "s/\([0-9]*:[0-9]*\)/`min2sec \1`/g"
the shell does now execute `min2sec \1`, however it does so before sed substitutes "\1" (before sed is even called, I believe). IOW sed is called as in the following line:
cat datafile.txt | sed "s/\([0-9]*:[0-9]*\)/`60`/g"
Do you see any way arround this problem? Is there any way to tell sed to execute a shell command? Or do I need to look for a solution outside of sed?
I looked to awk to solve my problem instead. The following code converts lines 1-4 into lines 5-7, which was the application I need. I'll just post the code here in case it helps anyone.
$1 == board, stop == 3 {
if ($1 != board)
{
printf "%s = [ ", $1;
for (i = 2; i <= NF; i++) {
n = split($i,x,":");
if ( n == 1 ) {
printf "%s ", $i;
}
else
{
printf "%d ", x[1]*60 + x[2];
}
}
printf "];\n"
}
stop++
}
I'm still interested in knowing whether it's possible to call a shell script from within awk or sed, however the above work-arround solves my problem for now. Thanks for the help.