0

I have the following test.txt file with two lines

keyword 1, 2010-10-01 | 1 | 2 | 3 | 4
keyword 2, 2010-10-01 | 1 | 2 | 3 | 4

and would like to ack for keyword1 and keyword2. I call this script

#!/bin/bash

OUTPUTPATH=$1"/"
JOB=$2
ID="_"$3".csv"

for keyword in "${@:4}"
do
        trKeyWord=$(echo "$keyword" | sed 's/ //g')
        ack \""$keyword"\" $JOB > $OUTPUTPATH$trKeyWord$BSLD_ID
done

via

bash script.sh /home/username/ test.txt test "keyword 1" "keyword 2"

The ouput files keyword1_test.csv, keyword2_test.csv are created but they are empty! The problem must be how I am using ack \""$keyword"\" $JOB because just running this command gives an empty result.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
tenticon
  • 2,639
  • 4
  • 32
  • 76

1 Answers1

2

Okay guys, this is the final (working) answer:

outputpath="$1"/
job="$2"
id=_"$3".csv
for keyword in "${@:4}"
do
  trKeyWord=${keyword// }
  ack "$keyword" $job > $outputpath$trKeyWord$id
done
tenticon
  • 2,639
  • 4
  • 32
  • 76
  • Woops, it appears that my answer was wrong and that this one is correct, congrats on the fix. –  Jan 09 '17 at 16:24
  • Be sure to quote your variables. If, say, `outputpath` was `my output dir` your redirection wouldn't work the way you want. Similar concerns for the `job` and the other variables as well – Eric Renouf Jan 09 '17 at 16:53