Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:01:02+00:00 2026-06-06T15:01:02+00:00

I’d like to write a parsing script in Perl that prints all the interface

  • 0

I’d like to write a parsing script in Perl that prints all the “interface name” from these bunch of data:

interfaces.ifTable.ifEntry.ifDescr.1 : OCTET STRING- (ascii): (hex): length = 30
    0:  53 6f 66 74 77 61 72 65 20 4c 6f 6f 70 62 61 63     Software Loopbac
    16:  6b 20 49 6e 74 65 72 66 61 63 65 20 31 00 -- --     k Interface 1...

interfaces.ifTable.ifEntry.ifDescr.2 : OCTET STRING- (ascii): (hex): length = 20
    0:  57 41 4e 20 4d 69 6e 69 70 6f 72 74 20 28 53 53     WAN Miniport (SS
    16:  54 50 29 00 -- -- -- -- -- -- -- -- -- -- -- --     TP).............

interfaces.ifTable.ifEntry.ifDescr.3 : OCTET STRING- (ascii): (hex): length = 20
    0:  57 41 4e 20 4d 69 6e 69 70 6f 72 74 20 28 4c 32     WAN Miniport (L2
    16:  54 50 29 00 -- -- -- -- -- -- -- -- -- -- -- --     TP).............

I’d like to extract all the three interfaces’ name out, as (“Sotware Loopback Interface 1”, “WAN Miniport (SSTP)”, “WAN Miniport (L2TP)”), and do further processing. I tried using regular expression but without luch. Is there any simple way to do this? Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:01:03+00:00Added an answer on June 6, 2026 at 3:01 pm

    This is yet another dirty perl script. Read your data into $text however you wish. The regular expression looks for the pattern of each hex dump line. The join line then recombines the hex values back into the string and appends it to the current accumulated interface name. mttrb’s is simpler. 😉

    $text =<<EOM;
    interfaces.ifTable.ifEntry.ifDescr.1 : OCTET STRING- (ascii): (hex): length = 30
        0:  53 6f 66 74 77 61 72 65 20 4c 6f 6f 70 62 61 63     Software Loopbac
        16:  6b 20 49 6e 74 65 72 66 61 63 65 20 31 00 -- --     k Interface 1...
    
    interfaces.ifTable.ifEntry.ifDescr.2 : OCTET STRING- (ascii): (hex): length = 20
        0:  57 41 4e 20 4d 69 6e 69 70 6f 72 74 20 28 53 53     WAN Miniport (SS
        16:  54 50 29 00 -- -- -- -- -- -- -- -- -- -- -- --     TP).............
    
    interfaces.ifTable.ifEntry.ifDescr.3 : OCTET STRING- (ascii): (hex): length = 20
        0:  57 41 4e 20 4d 69 6e 69 70 6f 72 74 20 28 4c 32     WAN Miniport (L2
        16:  54 50 29 00 -- -- -- -- -- -- -- -- -- -- -- --     TP).............
    EOM
    
    $interface = "";
    foreach $line (split(/\n/, $text)) {
      next unless $line =~ /\b(\d+):\s+((?:[0-9a-fA-F-]{2} ){16})/;
      if ($1 == 0) {
        print "$interface\n" if $interface;
        $interface = "";
      }
      $interface .= join('', map { chr(hex($_)) } grep { $_ ne '--' && $_ ne '00' } split(/ /, $2));
    }
    print "$interface\n" if $interface;
    

    To explain the join line, the following things occur in that line.

    1. split(/ /, $2) – Takes the second saved group from the regular expression, which are the hex characters, and splits it into an array containing each pair of digits.
    2. grep { $_ ne ‘–‘ && $_ ne ’00’ } – Looks through the digit pair array and filters out the ‘–‘ and ’00’ entries, leaving only valid values.
    3. map { chr(hex($)) } – Runs the expression against each of the filtered pairs, $ being the pair being processed. Hex parses it from a hex() string into a number and then chr() takes that number and translates it into the corresponding character.
    4. join(”, …) – Takes in the array of characters that map created and creates a single string out of them. The ” is the string to separate each array item with, in this case nothing.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a text area in my form which accepts all possible characters from
I'm parsing an XML file, the creators of it stuck in a bunch social
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.