Collecting information from TXT

Welcome Forums General PowerShell Q&A Collecting information from TXT

Viewing 5 reply threads
  • Author
    Posts
    • #194489
      Participant
      Topics: 1
      Replies: 2
      Points: 15
      Rank: Member

      Hi,

      I have created a small script that cleans an ARP cache and want only keep THE IP Adress and MAC adress, but it seem it does not working well for me. Im new into PS. Any expert there out that can help me?

       

      IP address         MAC address        VLAN       Interface       Aging Type
      10.99.146. 44     000b-abe3-a2df    133           JOG55          30  D
      10.120.155.167   b49c-df53-ffbb       133          JOG55           45   D

      The clean text is making everything harder.

      The script should return  semicolon separated list containing the  MAC and IP adress only but i dont make it work :(. Would love some help.

       

       

       

    • #194501
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      First, this appears to be very similar:

      Regex Match Multi-line Cisco Switch Config

      The clean text is making everything harder.

      Actually, the “clean text’ is an object, so it makes things easier. Powershell is very object oriented. Powershell cmdlets typically return and accept objects. You actually did the hard work to parse raw text into an object, now you can just use Export-CSV to create a csv.

      Using -replace uses a regex pattern, so you can simplify it using a pipe to represent OR and the overload for not passing a replacement is to use ” (e.g. nothing).

    • #194507
      Participant
      Topics: 1
      Replies: 2
      Points: 15
      Rank: Member

      Thank you soooo much , but the hard part is to remove , The VLAN and their Numbers without destroying the IP numbers same with 30 D, i think i need fix the pattern better.

    • #194513
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      If you can post some example text that you are parsing, it will be easier to test the code and see what is going on.

    • #194516
      Participant
      Topics: 1
      Replies: 2
      Points: 15
      Rank: Member

      IP address          MAC address
      10.99.146. 44       000b-abe3-a2df        133    30 D
      10.120.155.167      b49c-df53-ffbb          133        45 D

      PS C:\WINDOWS\system32

      Now this look good since i can build up the script for removing all VLans etc- but now the only problem is if i Replace “133”, 30 D etc the IP adresses will get mest up since im removing the 133 , this script will be used to collect Data.

      I tried to make a line that removes all text and only keeps the mac Adress and IP .

      hmmm

    • #194555
      Participant
      Topics: 5
      Replies: 328
      Points: 521
      Helping Hand
      Rank: Major Contributor
Viewing 5 reply threads
  • The topic ‘Collecting information from TXT’ is closed to new replies.