0

There's something I'm having trouble understanding concerning sed behavior.

sed -n "/pattern/,$p" < input.inp > output.out

gives the following error

sed: -e expression n°1, caractère 10: `,' inattendue

(my system is in french).

sed -n '/pattern/,$p' < input.inp > output.out

Works fine

I've personnally used commands like

sed -n "/begin/,/end/p" < input.inp > output.out

with both single or double quotes, and they work just fine.

In case it's useful, I have sed version: sed (GNU sed) 4.2.2

PsiX
  • 1,661
  • 1
  • 17
  • 35
user22277
  • 117
  • 2
  • 14

1 Answers1

3

In double quotes, the shell, not sed, will evaluate $p. Since you probably haven't set a variable named p, sed will only see /pattern/,. To prevent this from happening, you'd need to escape the $ to the shell, by writing \$ instead:

sed -n "/pattern/,\$p" < input.inp > output.out

(You can imagine that using single quotes is a lot easier on the eyes and brain, unless you need shell variables in your expression.)

Ulrich Schwarz
  • 7,598
  • 1
  • 36
  • 48