Perl + one-liner smart Perl command, in place grep to match unusual characters + full match

前端 未结 3 1154
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 00:14

Subject: one-liner smart Perl command instead of a simple grep (in Bash script)

I have a problem when I use grep to match the unusual characters (I can\'t put the \"\\\"

3条回答
  •  自闭症患者
    2021-01-28 00:57

    I'm not sure I understand your question, exactly. Perhaps -P and -x do what you want, along with quoting "$Some_string" to preserve whitespace?

    grep -Px "$Some_string" file
    

    From the grep man page:

    -P, --perl-regexp

    Interpret PATTERN as a Perl regular expression.

    -x, --line-regexp

    Select only those matches that exactly match the whole line.

提交回复
热议问题