0

I am trying to produce a .csv file in a Bash shell script. Please consider this code:

#!/bin/bash

for f1 in *_8_kHz.wav
do
   for f2 in *_8_kHz.wav
   do
      # echo "pesq +8000 $f1 $f2"
      echo -n `pesq +8000 $f1 $f2 | grep Prediction | rev | cut -b1-5 | rev`
   done

   echo
done

This works except, of course, that each line ends with a comma. Here is sample output:

4.500,1.029,1.651,1.475,1.698,1.706,
1.550,4.500,1.477,1.148,1.788,1.478,
1.251,0.958,4.500,1.472,2.091,1.800,
0.961,1.154,1.550,4.500,1.702,1.501,
1.194,0.974,1.356,1.206,4.500,1.626,
0.857,0.960,1.091,1.064,2.012,4.500,

What is the most efficient way to omit those trailing commas?

Dave
  • 1,519
  • 2
  • 18
  • 39

2 Answers2

0

Is the following efficient enough?

echo -n `pesq +8000 $f1 $f2 | grep Prediction | rev | cut -b1-5 | rev` | sed 's/,$//'

It is using sed to remove the last , before the end of the line $.

Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
0

from https://stackoverflow.com/a/18262725/2796606

foo=`pesq +8000 $f1 $f2 | grep Prediction | rev | cut -b1-5 | rev`

echo -n ${foo%?}
Community
  • 1
  • 1
seanrclayton
  • 157
  • 1
  • 7