1
grep -F "$name" -A1000 filename | sed -n '1p;19p;24p'

Assume let a=10,b=20,c=30.In the above grep command can I use '$ap;$bp;$cp' instead of '1p;19p;24p'?

Another thing, I've given as -A1000. Which implies that starting from 1p it considers till 1000 line , right? I need to search throughout file without giving the number.

thb
  • 13,796
  • 3
  • 40
  • 68
Jackie James
  • 785
  • 8
  • 15
  • 28

1 Answers1

6

If you want to include variables inside quotes, you need to use " instead of '.

If you want to add alphanumeric suffix to a variable you need to indicate that it's not part of it's name.

sed -n "${a}p;${b}p;${c}p"

Or:

sed -n "$a"'p;'"$b"'p;'"$c"'p'
Paul
  • 139,544
  • 27
  • 275
  • 264
Piotr Praszmo
  • 17,928
  • 1
  • 57
  • 65