A
A
Andrey Bondarchuk2019-06-14 08:35:06
Perl
Andrey Bondarchuk, 2019-06-14 08:35:06

How to extract a number/word after a specific character (perl, regular expressions)?

Good afternoon!
At the moment, I have a script that accesses the equipment via telnet, asks for information about the piece of iron, enters it into an array, and then extracts a string from the array containing the sequence of characters "No.:"

@line = $t->cmd(Timeout => 120, String =>'show version'); 
@result = grep/\s(No.:)/, @line; 
print @result;

Result:
Serial No.:ABCD1234EF56 Can you tell me
how to extract the characters after the ":" sign?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2019-06-14
@sh1kima26

You can do without regulars:

my $a =  join(",", @result);
my @res = split(":", $a); 
print $res[1]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question