473,503 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invert return value of grep command?

32 New Member
If grep is successful it returns 0 - how can I change it so that it returns a value other than 0?

thank you
Apr 3 '09 #1
3 7863
ghostdog74
511 Recognized Expert Contributor
use the -v option of grep
Apr 4 '09 #2
gary turner
1 New Member
I've been very frustrated at repeatedly finding this answer to this question, which is in fact completely unhelpful.
Using -v will return 0 for any file that contains lines that don't contain the search pattern, which is generally true, and therefore generally useless!
The 'real' answer IMHO is that you need to do this using your OS/shell to reverse the return code. On Win32 >Win2k you can use this:
cmd /c "grep pattern $< & if not ERRORLEVEL 1 exit 1"
I imagine that on unix shells this should be simpler and less cryptic, but will leave that to someone more expert than myself to comment on should they care.
Mar 5 '12 #3
no2pencil
4 New Member
My apologies if I don't understand the question, but in regards to grep returning zero upon sucess :

hpweb# cat xd_receiver.htm | grep facebook
hpweb# echo $?
0
hpweb# cat xd_receiver.htm | grep FACEBOOK
hpweb# echo $?
1
Mar 5 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2874
by: Des Small | last post by:
Lately I have found myself using a pattern to make new dictionaries quite often, by which I mean twice: def invert(d): nd = {} ).append(key) for k, v in d] return nd def count(l): d = {}
5
4908
by: Stan | last post by:
hi, Could any one give me an advice of providing a regular expression that will return all non-blank lines in a file in linux. Maybe it is just a command! Thanks Stan
3
2199
by: E.U. | last post by:
Hello, I need to program grep (like the one UNIX has but more simple) For example if the programs name(the grep I will write) is p3 then if I write in shell p3 story.txt word The output...
4
2041
by: Derek Martin | last post by:
Hi List, I have an arraylist of objects. I have created my own IComparable in the object to return the sort on datetime. This works great! Now, I'd like to invert the sort. Currently, it gives...
4
3218
by: agarwalpiyush | last post by:
Hello, I am going nuts with trying to get the following to work: This is what I intend to do: I have a line in /etc/syslog.conf which I need to delete based on ip-address provided to me in a...
41
3336
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
1
2879
by: mahesh.nimbalkar | last post by:
Hi, I have color as System.Drawing.Color c1 object as background color. Now I would like to get another System.Drawing.Color c2 object which is invert of c1 color to be used as foreground...
4
1705
by: dave | last post by:
Hello, here is a piece of code I wrote to check the frequency of values and switch them around to keys in a new dictionary. Just to measure how many times a certain key occurs: def...
47
3380
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.