473,396 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3555
numberwhun
3,509 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,509 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,509 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,509 Expert Mod 2GB
Kevin,

I sent you a PM.

Jeff
Jul 6 '07 #10

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

Similar topics

14
by: Xah Lee | last post by:
Just bumped into another irresponsibility in perl. the crime in question this time is the module File::Basename. Reproduction: 1. create a directory containing a file of this name:...
31
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
1
by: Al Belden | last post by:
Hi all, I've been working on a problem that I thought might be of interest: I'm trying to replace some korn shell scripts that search source code files with perl scripts to gain certain features...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
4
by: js | last post by:
Just my curiosity. Can python beats perl at speed of grep-like processing? $ wget http://www.gutenberg.org/files/7999/7999-h.zip $ unzip 7999-h.zip $ cd 7999-h $ cat *.htm bigfile $ du -h...
3
by: soniamadtha | last post by:
hello everyone, i have the following values : 98000345 and i would like to search this value in all of the sql files in the directory /temp/*sql normally on unix its grep( ' 98000345 '...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.