0

I type this line in zsh to find a backslash followed by a lowercase n:
pdfgrep "\\n" <some path>
(P.S. pdfgrep, doing grep on PDFs)

Then zsh will first escape double backslash into a single backslash, resulting in what pdfgrep see is "\n" <some path>, i.e. searching for a line feed (LF).

How to prevent zsh from first escaping backslash in arguments to command?

SkyLian
  • 1
  • 1

1 Answers1

0

hello, hope you are doing well,

Thank you for your question, I didnt know pdfgrep :p

First, I downloaded a pdf (this one exactly https://www.docker.com/wp-content/uploads/2022/03/docker-cheat-sheet.pdf)

then I tried the simple:

❯ pdfgrep '\n' docker-cheat-sheet.pdf

but didnt work as you know.

Then like you, I tried this:

pdfgrep '\\n' docker-cheat-sheet.pdf

but there was no output.

I decided to try to escape the \n with an echo command to test:

as expected, this interprete the \n:

❯ echo -e "test\ntest"
test
test

then I tried this, but it didnt work also:

❯ echo -e "test\\ntest"
test
test

then I tried this, and it worked with the echo command:

❯ echo -e "test\\\ntest"
test\ntest

So i decided to try it on the pdf, but still no output:

❯ pdfgrep '\\\n' docker-cheat-sheet.pdf

then, I have found this topic: pdfgrep pattern to include/exclude linebreak

and tried this:

❯ pdfgrep -P '\n' docker-cheat-sheet.pdf

I think this do the job, is it what you was looking for?

bguess

Bguess
  • 1,700
  • 1
  • 11
  • 24
  • No. It's not RegExp Engine's problem, so whether ```-P``` doesn't matter. Actually finding ```\\n``` is just a special example; the general problem is preventing escaping backslash, like that in ```\\d```(number otherwise), ```\\b```(word boundary otherwise), ```\\r```(carriage return otherwise). – SkyLian Apr 23 '22 at 06:45
  • Ok Let's just resume to better understand, when you pdfgrep a PDF with \n you want to grep New Lines or the opposite, meaning you want to grep the character "\n"? – Bguess Apr 23 '22 at 06:50
  • Every word is positive, but what do you mean by "the opposite"? – SkyLian Apr 23 '22 at 07:31
  • meaning you want to grep exactly the pattern "\n" ? (sorry for my english) – Bguess Apr 23 '22 at 16:37
  • But wait, no output to "pdfgrep '\\n' docker-cheat-sheet.pdf" or "pdfgrep '\\n' docker-cheat-sheet.pdf" means that there is no "\n" pattern in the pdf right? – Bguess Apr 23 '22 at 16:40