4

I want to check the absence of the following sequence of characters $$$$$ (i.e., 5 dollar signs) in a json file using grep as it has been used instead of comma to separate fields and I need to make sure this did not cause conflicts with existing similar sequence.

However, when I grep $, I get similar number of lines. It seems that $ is a special character for end of line?

How can i search for $$$$$ using grep? Is $ a special character?

  • In addition, in shell unquoted $$ is a special parameter which is replaced by the PID of the shell; this is commonly (and traditionally) used to create unique/nonconflicting names for temp-files and such. – dave_thompson_085 Dec 30 '18 at 20:49

1 Answers1

18

It seems that $ is a special character for end of line?

Yep, exactly. And there's an end-of-line on each and every line.

You'll need to use \$\$\$\$\$ as the pattern, or use grep -F '$$$$$', to tell grep to use the pattern as a fixed string instead of a regular expression.

Or a shorter version regex pattern: \$\{5\} in basic regex or \${5} in extended regular expressions (grep -E).

(In basic regular expressions (plain grep), you really only need to escape the last dollar sign, so $$$$\$ would do instead of \$\$\$\$\$. But in extended (grep -E) and Perl regular expressions they all need to be escaped so better do that anyway.)

ilkkachu
  • 138,973