Results 1 to 3 of 3
I am stroirng following output to the file(abc.tmp) :
Command := wget Google
[B]output[=/B]
--12:01:47-- Google
=> `index.html.2'
Connecting to 192.168.2.63:8214... connected.
Proxy request sent, awaiting response... 407 Proxy Authentication ...
- 02-02-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 1
Grep with regular expression
I am stroirng following output to the file(abc.tmp) :
Command := wget Google
[B]output[=/B]
--12:01:47-- Google
=> `index.html.2'
Connecting to 192.168.2.63:8214... connected.
Proxy request sent, awaiting response... 407 Proxy Authentication Required
12:01:47 ERROR 407: Proxy Authentication Required.
I want to write shell script to grep the file and check if it contains 407 Proxy Authentication Required
How do i do that?
Thanks in advance for ur help
- 02-02-2009 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Grep in quiet mode. A return code of zero means grep found it.
Code:grep -q '407 Proxy Authentication Required' abc.tmp if [ $? -eq 0 ]; then echo "Found it"; fi
- 02-05-2009 #3
A more elegant (and more common) way of writing vsemaska's solution would be:
if's condition evaluates to true if the program returns a 0 (successful) exit status. The "if [ ... ]" notation is actually a hidden call to a program called test, which treats its arguments as a more standard boolean arithmetic (1 = true, 0 = false, etc.) and returns success if true and failure otherwise.Code:if grep -q '407 Proxy Authentication Required'; then echo "Found it" fi
grep's "-q" option means "Instead of printing out lines, just check if there's a match. If there is, return success; otherwise return failure".
I hope this helps.DISTRO=Arch
Registered Linux User #388732


Reply With Quote