header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Formatting text in a variable from .txt file
Last Post 15 Jan 2011 02:13 PM by RHodge. 0 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
RHodgeUser is Offline
New Member
New Member
Posts:1
Avatar

--
15 Jan 2011 02:13 PM
    I am hoping someone out there can give me a hand with this, I am close to figuring out but new to PowerShell...what else is new! In the $variable from reading in a text file, I have lines of text, each line has several columns, seperating the columns are spaces and tabs. What I want to do is replace the spaces and tabs with just one tab and delete everything after the "/" including the "/". Is this possible? Here is a sample, the "!" are the sapces and "*" are tabs. The amount of spaces and tabs varies between lines...

    Example:

          # Computer information
          # Column 1 computer name
          # Column 2 IPaddress
          # Column 3 Parent AD
          #

       comp-79345-sdc!!!!!!**192.168.1.1/24!!!!!!***ads-23457-sda
       comp-79346-sdc!!!!!!!**192.168.1.2/24!!!!!!!!!**ads-23457-sda

    Here is the code I have come up with to replace spaces and tabs with a "+" and delete all the lines with "#" in front. I can also out put to a new file.

    $NetDef = Cat -path ("c:\Config-dir\Config-data\Net-def\network*.txt") | ForEach-Object {$_ 
       -replace "\s","+"} | where { $_ -notlike "*#*"}
    $NetDef | Out-File C:\config-dir\Config-data\DNSNetDef.txt

    Any help would be greatly appreciated!

    Thanks.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer