-3

I am currently using grep like this:

grep search_string search_file > output_file

Here is an example:

grep "ich arbeite" deu.txt > out.txt

When used in this way, I only get the last 20 matches in out.txt. I think this is because the search_string contains a space and quotation marks, because when I try:

grep arbeite deu.txt > out.txt

...I get the expected result (all matches show up in out.txt)

How can I get grep to return all matches when I search for a string containing spaces?

EDIT: My input looked like this:

...
I wonder why.   Ich frage mich, warum.
I work a lot.   Ich arbeite viel.
I'll ask Tom.   Ich frage mal Tom.
...
I wish Tom wouldn't keep bothering me with questions.   Ich wünschte, Tom würde aufhören, mich mit Fragen zu nerven.
I wonder if Tom realizes how many hours a day I work.   Ich frage mich, ob Tom klar ist, wie viele Stunden täglich ich arbeite.
...

closed as off-topic by Michael Homer, Stephen Kitt, Anthon, Archemar, X Tian Jun 19 '15 at 11:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Michael Homer, Stephen Kitt, Anthon, Archemar, X Tian
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    grep always returns all matches; something else is going on. – Michael Homer Jun 19 '15 at 7:38
  • @Michael Homer My initial search string was "ich arbeite" with the quotation marks. When I tried just arbeite without quotations it gave the full output. – Greg Jun 19 '15 at 7:42
  • 1
    Does that mean your issue is resolved? Otherwise, you can edit in details of what you're actually doing and what the actual results are versus what you expect. – Michael Homer Jun 19 '15 at 7:44
  • For the case that I'm currently trying it's resolved, but I would like to be able to search for strings containing spaces in the future. – Greg Jun 19 '15 at 7:46
  • 1
    (Include some sample input from your file as well as the commands) – Michael Homer Jun 19 '15 at 7:53
1

It turns out that using quotations as I had done returns only case-sensitive matches (of which there were exactly 20). Changing the search_string to

"Ich arbeite"

subsequently returned all the matches where the first 'I' is uppercase. The reason why I hadn't noticed that was because most of the early matches that I was looking for had the I in uppercase, while the later matches which I wasn't looking for had the I in lowercase.

  • 2
    You can use grep's -i flag to trigger case-insensitive matches next time ;-) – Wouter Verhelst Jun 19 '15 at 8:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.