Grep inline use perl

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Grep inline use perl
# 1  
Old 01-24-2013
Grep inline use perl

Hi,

i have input like this :
Code:
SS-ID VLAN MAC               TIME IP                 RSSI MODE  UAPSD BW GI WMOS DHCP       IDENTITY 
----- ---- ---               ---- --                 ---- ----  ----- -- -- ---- ----       -------- 
1-1   0    C4:46:19:75:C1:55 23m  192.168.5.253      -24  bgn   no    20 S  4.9  ack* 
1-2   0    5C:57:C8:69:8C:1E 3s   192.168.5.254      -38  bg    no    20 L  4.8  ack*




I want the output is "1-1" by grep in line by MAC Address

So far i use this scripts, but doesn't work :

Code:

my @macall = qw(print @input); 
    foreach $line (@macall) { 
        if ($line =~ /C4:46:19:75:C1:55:\s+(\S+)/) { 
                $id = $1; 
            } 
        } 
      print "ID = $id"; 
      return (0);


Anybody can help ?
# 2  
Old 01-24-2013
Code:
 
$ cat a.txt
SS-ID VLAN MAC               TIME IP                 RSSI MODE  UAPSD BW GI WMOS DHCP       IDENTITY 
----- ---- ---               ---- --                 ---- ----  ----- -- -- ---- ----       -------- 
1-1   0    C4:46:19:75:C1:55 23m  192.168.5.253      -24  bgn   no    20 S  4.9  ack* 
1-2   0    5C:57:C8:69:8C:1E 3s   192.168.5.254      -38  bg    no    20 L  4.8  ack*
 
 
$ perl -lane 'if($_=~/C4:46:19:75:C1:55/){print $F[0];}' a.txt
1-1

# 3  
Old 01-24-2013
what about if i wanna use the perl scripts ?
not use the command?
# 4  
Old 01-24-2013
I believe this is the best way of doing it! Rather writing 10-20 lines of code for this simple task! Smilie
# 5  
Old 01-24-2013
Code:
        if($line=~/C4:46:19:75:C1:55/)
        {
                my @F=split(/ /,$line);
                print $F[0];
        }

# 6  
Old 01-24-2013
Quote:
Originally Posted by itkamaraj
Code:
        if($line=~/C4:46:19:75:C1:55/)
        {
                my @F=split(/ /,$line);
                print $F[0];
        }

I thought to write a new program for this. Smilie

My bad!!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl inline replace only on 1st line

I have file file_1.out which contains the data below <tr> MAIL # 1 TO src_1 </tr> <tr><td class="hcol">col_id</td> <td class="hcol">test_dt</td> <td class="hcol">user_type</td> <td class="hcol">ct</td></tr> <tr><td class="bcol">1</td> <td class="bcol">2012-09-20</td> <td class="bcol">A</td>... (4 Replies)
Discussion started by: sol_nov
4 Replies

2. Programming

Perl : Inline program to determine file size

Hi, I have 5 files as below $ ll sam* -rw-rw-rw- 1 sam ugroup 0 Mar 21 06:06 sam3 -rw-rw-rw- 1 sam ugroup 0 Apr 3 22:41 sam2 -rw-rw-rw- 1 sam ugroup 17335 Apr 10 06:07 sam1 -rw-rw-rw- 1 sam ugroup 5 Apr 10 07:53 sam5 -rw-rw-rw- 1 sam ugroup 661 Apr 10 08:16 sam4 I want to list out... (4 Replies)
Discussion started by: sam05121988
4 Replies

3. Post Here to Contact Site Administrators and Moderators

inline code tags

How to add inline tags in the posts? Like in this thread post #4. Thanks. (5 Replies)
Discussion started by: clx
5 Replies

4. Shell Programming and Scripting

Scripting for inline input

Hello, I'm not much familiar with scripting, just a little bit. Maybe someone could give an advice how implement my task. It might be in shell or perl. I have linux system where I install Kerberos. Now I have to add user. It's done like this from prompt: 1. run kadmin.local 2. it switches to... (1 Reply)
Discussion started by: susja
1 Replies

5. UNIX for Advanced & Expert Users

inline redirect stdin

Hi: I have the next script on ksh #!/usr/bin/ksh cd $FUENTES qdesign <<-! \$/opt/cognos/ph843e/bin/qtp <<-! \$/opt/cognos/ph843e/bin/quiz <<-! ! ! ! This script is very simple, i want to nest three process quiz into qtp, and this into qdesign. When I run it , i receive the next... (2 Replies)
Discussion started by: ct2marer
2 Replies

6. Shell Programming and Scripting

inline redirect stdin

Hi: I have the next script on ksh #!/usr/bin/ksh cd $FUENTES qdesign <<-! \$/opt/cognos/ph843e/bin/qtp <<-! \$/opt/cognos/ph843e/bin/quiz <<-! ! ! ! This script is very simple, i want to nest three process quiz into qtp, and this into qdesign. When I run it , i receive the... (5 Replies)
Discussion started by: ct2marer
5 Replies

7. Programming

Inline function inside Classes

#include <iostream> using namespace std; class A { public: int Getvalue() { return i;} private: int i; }; int main() {} The above code compiles properly in g++ or in any other C++ compiler. BUT, the variable 'i' is used (in 'return i' statement) before it is... (1 Reply)
Discussion started by: deepthi.s
1 Replies

8. Shell Programming and Scripting

Array Printing Inline

Dear friends , The output file of below script Pls#!/bin/sh awk '{ bo = substr($0,13,3) slm = substr($0,150,8) slo = substr($0,175,7) inc = substr($0,97,10)/100 busi = substr($0,83,10) mth = substr($0,39,2) yer = substr($0,35,4) ... (2 Replies)
Discussion started by: vakharia Mahesh
2 Replies

9. Shell Programming and Scripting

Inline Parameters-Urgent

Can someone tell me how to enter inline parameters with script call? This is a little urgent so some help would be highly appreciated. Thanks a lot. Indira (2 Replies)
Discussion started by: indira
2 Replies
Login or Register to Ask a Question