Need to grep 2 words from Perl Script results in Terminal....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to grep 2 words from Perl Script results in Terminal....
# 1  
Old 04-18-2010
Need to grep 2 words from Perl Script results in Terminal....

Hey guys. I have a .pl script that scans my hosts to see if they are down or up. I can run it anytime I want. The script uses a conf file that contains text lines of the IP addresses of the servers. I run the script from the command line of my terminal (MAC OS)

I run:
Code:
sudo ./scanner.pl

brings back:
Code:
10.0.1.1 - DOWN

10.0.1.2 - DOWN

10.0.2.3 - UP

10.0.2.4 - DOWN

10.0.3.5 - UP

10.0.3.6 - UP

I want to only have displayed for me the results of the two xx.x.3.x results

but if I run this:

Code:
sudo ./scanner.pl | grep 3

OR
Code:
sudo ./scanner.pl | grep UP

then I get this:

10.0.2.3 - UP

10.0.3.5 - UP

10.0.3.6 - UP



But I only care about the last 2 results (3.5 and 3.6)

so I tried:

sudo ./scanner.pl | grep UP 3.
hoping that it would be able to grab the lines that have both of those parameters, but that doesnt work....

How do I specify 2 things to grab from one line?

For Example, I only want to display:
Code:
10.0.3.5 - UP

10.0.3.6 - UP


THANKS IN ADVANCE

Last edited by Yogesh Sawant; 04-18-2010 at 03:00 PM.. Reason: added code tags
# 2  
Old 04-18-2010
Code:
sudo ./scanner.pl | perl -wlne '/\d+.\d+.3.\d+.*/ and print ;'

SmilieSmilieSmilie
# 3  
Old 04-18-2010
Code:
sudo ./scanner.pl | awk -F. '$3==3'

# 4  
Old 04-18-2010
Quote:
Originally Posted by yoyoyo777
...
so I tried:

sudo ./scanner.pl | grep UP 3.

hoping that it would be able to grab the lines that have both of those parameters, but that doesnt work....

How do I specify 2 things to grab from one line?

...
By using a regex that has both the search patterns in each line.

Code:
$
$ ./scanner.pl
10.0.1.1 - DOWN

10.0.1.2 - DOWN

10.0.2.3 - UP

10.0.2.4 - DOWN

10.0.3.5 - UP

10.0.3.6 - UP

$
$ ./scanner.pl | grep "3.[56] - UP"
10.0.3.5 - UP
10.0.3.6 - UP
$
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot get results from grep command

Hi, i have a file hello.log which as several line that look like the below 2015-12-07 09:46:56 0:339 120.111.12.12 POST /helloWorld 2015-12-07 09:46:57 0:439 122.111.12.12 POST /helloWorld .... when i grep expecting to see results like the below. ... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

How to change Linux Terminal environment variable in a perl or bash script?

Hi, I meet an problem that it cannot change Terminal environment variable in a perl or bash script. This change can only exist and become effective in script lifetime. But I want to make this change take effect in current opened Terminal. In our view, the thought seems to be impossible, As... (9 Replies)
Discussion started by: weichanghe2000
9 Replies

3. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

4. Programming

Unix grep in perl script

Hello, Fairly simple really I have an xml file and I want to check to see if it contains a pattern. The pattern is "../" On the command line I can type: grep "\.\./" myFile.xml and I get desired result. To do the same thing in a perl script I thought it was as simple as putting the ``... (4 Replies)
Discussion started by: Jaymoney
4 Replies

5. Shell Programming and Scripting

Grep no results

Hello guys, I have been looking around but can't find the answer to my problem: If the grep command displays no results, print "no results have been found" and increment x. But if the grep command find something, do nothing. if echo "no results have been found $x" x=`expr $x + 1 `... (3 Replies)
Discussion started by: Benou
3 Replies

6. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

7. Shell Programming and Scripting

Perl Script to find & copy words from Web.

I need to write a perl script to search for a specific set of numbers that occur after a series of words but before another. Specifically, I need to locate the phrase today at the summit, then immediately prior to the words tonnes/day copy the number that will be between 100 and 9,999, for example,... (1 Reply)
Discussion started by: libertyforall
1 Replies

8. Shell Programming and Scripting

strpping words - perl script

hi below is a regex that i have framed to strip some bad words from my text. ... (3 Replies)
Discussion started by: Sgiri1
3 Replies

9. Shell Programming and Scripting

grep ^M in file using perl script....

hi i am using perl on windows ( active state perl 5.8 ) and i want to check for Control-M (^M) in file. files to be checked are in unix format so new line character is (\n). This perl script is called from Batch file ( windows .BAT file ) my script is while (<PROGRAM>) { ... (12 Replies)
Discussion started by: zedex
12 Replies

10. Shell Programming and Scripting

How to refine results of grep -p

I need help to further reduce the output shown below. I want to be able to only return the paragraph where the 'Database alias' is exactly equal to DBIHP. I do not want the other paragraphs being shown below. $ echo $dbalias DBIHP $ db2 list db directory|grep -p 'Database alias ... (2 Replies)
Discussion started by: priceb
2 Replies
Login or Register to Ask a Question