0

I have need to define a variable in a bash script in a grep commad as below

#!/bin/bash
DATA=502
DataGet=501
for i in  1 2 44 45
do
GET=$(echo "$i" "$DATA" | awk '{print $1*$2}')
rm $GET.dat
grep '   501   ' -A"$GET"  case.dat | head -n "$GET" | tail -n "$DataGet" > $i.dat
done

Instead of the seond last line, I want to have

grep ' "$DataGet" ' -A"$GET" case.dar | head -n "$GET" | tail -n "$DataGet" > $i.dat

but it does not print anything.

astha
  • 593
  • 5
  • 15

1 Answers1

3

You should use double quotes to evaluate the variable.

~ > b=123
~ > echo '$b'
$b
~ > echo "$b"
123

So change your first string to this:

grep " \"$DataGet\" " -A "$GET" ...
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
Matt Clark
  • 27,671
  • 19
  • 68
  • 123