469,352 Members | 1,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

pure perl versus grep -v in unix

what should I use in perl /in place of grep -v in unix.
Jul 6 '07 #1
9 3448
numberwhun
3,503 Expert Mod 2GB
Well, that depends. You could learn how to use Perl Regular Expressions and get really creative, or you could use back tics and use `grep -v`. (that is what I would probably do it I didn't have time to mess with the regex)

Regards,

Jeff
Jul 6 '07 #2
hi Jeff ..thanks a lot for ur quick response I have tried it but still having issues.
This is how i m using this system("zcat $file | grep -i TYPE=ERROR | `grep -v` BackendResponseException > /tmp/err.2wd")

getting following on running

sh: BackendResponseException: not found
Usage: grep -hblcnsviw pattern file . . .

can anyone please suggest sth on this
Jul 6 '07 #3
miller
1,089 Expert 1GB
backticks are used in perl, but that string passed to the system command is a system level operation. Therefore don't use the backticks.

Expand|Select|Wrap|Line Numbers
  1. system("zcat $file  | grep -i TYPE=ERROR | grep -v BackendResponseException > /tmp/err.2wd")
  2.  
Obviously try to get any system command to work at the command prompt first and then paste it into your perl code.

- Miller
Jul 6 '07 #4
numberwhun
3,503 Expert Mod 2GB
backticks are used in perl, but that string passed to the system command is a system level operation. Therefore don't use the backticks.
Is that just a "best practices" thing? I ask only because the result should be the same, yes?

Regards,

Jeff
Jul 6 '07 #5
KevinADC
4,059 Expert 2GB
you should generally not use a function or operator that returns results, in a void context, like backtiks:

Expand|Select|Wrap|Line Numbers
  1. `command`; # backtiks used in void context
system() does not return results (it returns the exit value) from the program/application so is good for running commands that output results somewhere else, like a file. system() also does some "magical" things with the arguments passed to it. See the system() docs for details:

perldoc system()
Jul 6 '07 #6
miller
1,089 Expert 1GB
I'm sorry, I wasn't very clear.

All I meant to point out was that using backticks "inside" the system command was wrong. Using backticks instead of a system command would be just fine, and is in fact how the majority of coders I've observed tend to do such things.

- Miller
Jul 6 '07 #7
KevinADC
4,059 Expert 2GB
I'm sorry, I wasn't very clear.

All I meant to point out was that using backticks "inside" the system command was wrong. Using backticks instead of a system command would be just fine, and is in fact how the majority of coders I've observed tend to do such things.

- Miller

that was subtle, I missed it myself:

system("zcat $file | grep -i TYPE=ERROR | `grep -v` BackendResponseException > /tmp/err.2wd")

backtiks, literally, in the system command
Jul 6 '07 #8
numberwhun
3,503 Expert Mod 2GB
that was subtle, I missed it myself:

system("zcat $file | grep -i TYPE=ERROR | `grep -v` BackendResponseException > /tmp/err.2wd")

backtiks, literally, in the system command
Oh, ok. I see now. I was curious because I knew that system returned a return code, but if you were doing something, system wise, that returned a value, then you almost HAVE to use backtics. (not to mention, if it was a bad practice, then I have been doing some very bad coding). :-)

Thanks for the clarification, both of you!!!

Regards,

Jeff
Jul 6 '07 #9
numberwhun
3,503 Expert Mod 2GB
Kevin,

I sent you a PM.

Jeff
Jul 6 '07 #10

Post your reply

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

Similar topics

14 posts views Thread by Xah Lee | last post: by
31 posts views Thread by surfunbear | last post: by
1 post views Thread by Al Belden | last post: by
reply views Thread by Kirt Loki Dankmyer | last post: by
135 posts views Thread by Xah Lee | last post: by
4 posts views Thread by Ignoramus6539 | last post: by
3 posts views Thread by soniamadtha | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.