Joe Kasavage
Joe Kasavage

Reputation: 522

Grep not stopping

I'm quite new to bash/shell scripting and can't seem to figure this out. While executing a bash script it stalls on a grep command. The Terminal just stops doing anything and you have press CTRL+Z to stop the script. I do not see a problem with the command line itself.

Code:

DATE="01-Apr-14"

grep 'error' | grep -v 'PHP Notice\|PHP Warning\|File does not' ~/Desktop/Servers/Folder/Error/Error_$DATE.txt >> ~/Desktop/Review/Folder_Review_$DATE.txt

Any help is greatly appreciated.

Upvotes: 1

Views: 5498

Answers (5)

DonCarleone
DonCarleone

Reputation: 869

ctrl + D will send an EOL symbol.

This helped for me.

Upvotes: 0

Shanmu
Shanmu

Reputation: 3

I had the same issue. Try pressing Ctrl + c.

It worked for me.

Upvotes: 0

Elliott Frisch
Elliott Frisch

Reputation: 201537

Your first grep is reading stdin. I think you wanted

grep 'error' ~/Desktop/Servers/Folder/Error/Error_$DATE.txt | \
  grep -v 'PHP Notice\|PHP Warning\|File does not' \
  >> ~/Desktop/Review/Folder_Review_$DATE.txt

Upvotes: 0

Juan Diego Godoy Robles
Juan Diego Godoy Robles

Reputation: 14975

You mixed grep orientation:

 grep 'error' ~/Desktop/Servers/Folder/Error/Error_$DATE.txt| grep -v 'PHP Notice\|PHP Warning\|File does not'  >> ~/Desktop/Review/Folder_Review_$DATE.txt

Upvotes: 3

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137557

grep 'error' is expecting its input from standard in. If you're not providing any input (via the keyboard, a pipe, etc), then it will block indefinitely.

Upvotes: 5

Related Questions