Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing parens

Status
Not open for further replies.

macubergeek

IS-IT--Management
Dec 29, 2004
41
US
when I do arp -a I get this kind of output:
(192.168.1.1)
(192.168.1.5)
(192.168.1.100)
(192.168.1.101)
(192.168.1.255)

All I want to do is to remove the parens and keep the ip address. I've tried this with sed and gotten nowhere.
sed 's/\(//g'
 
Code:
open FH1, "<arp-a.txt";
open FH2, ">arp-b.txt";
while (<FH1>) {
  chomp;
  @array=split //,$_ ;
  pop @array;
  unshift @array;
  print FH2, join ('',@array);
}
close FH1;
close FH2;
NOT tested ;-)

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Sorry
perhaps I was unclear
This is the output I want:
when I do arp -a I get this kind of output:
192.168.1.1
192.168.1.5
192.168.1.100
192.168.1.101
192.168.1.255

Now I'm thinking this is a simple regex find and delete. I'm just uncertain how to match ( and ) and replace with empty string.
 
If I'm understanding you, then you want to remove all parens. If so, try this:
Code:
#!/usr/bin/perl

use strict;
use warnings;

my @linky = qw/(192.168.1.1) (192.168.1.5) (192.168.1.100) (192.168.1.101) (192.168.1.255)/;

foreach my $arp(@linky) {
           zap_parens($arp);
}

sub zap_parens {
  my $raw_number = shift;
  $raw_number =~ s/[()]//g;
  print "$raw_number\n";
}
OUTPUT ->
192.168.1.1
192.168.1.5
192.168.1.100
192.168.1.101
192.168.1.255

I cannot claim this code as my own... it came from a higher place.

Let us know your results!

X
 
Code:
[b]#!/usr/bin/perl[/b]

@ips = qw/(192.168.1.1) (192.168.1.5) (192.168.1.100) (192.168.1.101) (192.168.1.255)/;

foreach (@ips) {
  s/(\(|\))//g;
  print"$_\n";
}


Kind Regards
Duncan
 
Wow
thanks guys
I'm on target now
I gotta grok regular expressions better....

**runs to re read regex book

jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top