문제

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.

도움이 되었습니까?

해결책 2

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

다른 팁

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.

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

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

It worked for me.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top