Windows Vista Forums

How to Skip comment in text - GC file.txt

  1. #1


    techstarts Guest

    How to Skip comment in text - GC file.txt

    I have below file called servers.txt
    --------------------------------------------------------
    #Hostnames should be lower caps
    Server1
    Server2
    Server3
    #Server4
    Server5
    ----------------------------------------------------------
    I would like to put some comment in the text file which powershell
    should skip it. is it possible. e.g. I do not want powershell to read
    anything which starts with #

    Thank you in Advance

      My System SpecsSystem Spec

  2. #2


    Vadims Podans [MVP] Guest

    Re: How to Skip comment in text - GC file.txt

    gc servers | ?{$_ -notmatch "^#"}
    --
    WBR, Vadims Podans
    MVP: PowerShell
    PowerShell blog - www.sysadmins.lv

    <techstarts@xxxxxx> rakstija zinojuma
    "news:a852e49f-3c62-4dc2-b41c-9c3d0587ffad@xxxxxx"...

    > I have below file called servers.txt
    > --------------------------------------------------------
    > #Hostnames should be lower caps
    > Server1
    > Server2
    > Server3
    > #Server4
    > Server5
    > ----------------------------------------------------------
    > I would like to put some comment in the text file which powershell
    > should skip it. is it possible. e.g. I do not want powershell to read
    > anything which starts with #
    >
    > Thank you in Advance

      My System SpecsSystem Spec

  3. #3


    techstarts Guest

    Re: How to Skip comment in text - GC file.txt

    On Jun 4, 3:04*pm, "Vadims Podans [MVP]" <vpodans> wrote:

    > gc servers | ?{$_ -notmatch "^#"}
    > --
    > WBR, Vadims Podans
    > MVP: PowerShell
    > PowerShell blog -www.sysadmins.lv
    >
    > <techsta...@xxxxxx> rakstija zinojuma
    > "news:a852e49f-3c62-4dc2-b41c-9c3d0587ffad@xxxxxx"....
    >
    >
    >

    > > I have below file called servers.txt
    > > --------------------------------------------------------
    > > #Hostnames should be lower caps
    > > Server1
    > > Server2
    > > Server3
    > > #Server4
    > > Server5
    > > ----------------------------------------------------------
    > > I would like to put some comment in the text file which powershell
    > > should skip it. is it possible. e.g. I do not want powershell to read
    > > anything which starts with #
    >

    > > Thank you in Advance
    Again thank you very much. Problem solved.
    Do I know what ^ does ?


      My System SpecsSystem Spec

  4. #4


    Matthias Tacke Guest

    Re: How to Skip comment in text - GC file.txt

    techstarts@xxxxxx wrote:

    > Again thank you very much. Problem solved.
    > Do I know what ^ does ?
    >
    You should.
    At least after having read:
    get-help about_regular_expressions
    or the online version
    http://go.microsoft.com/fwlink/?LinkId=133231

    Regards
    Matthias

      My System SpecsSystem Spec

  5. #5


    Vadims Podans [MVP] Guest

    Re: How to Skip comment in text - GC file.txt

    ^ means that pattern must match at string begining.
    --
    WBR, Vadims Podans
    MVP: PowerShell
    PowerShell blog - www.sysadmins.lv

    <techstarts@xxxxxx> rakstija zinojuma
    "news:96452047-f04c-48a8-a198-4a5d8c0900f8@xxxxxx"...

    > On Jun 4, 3:04 pm, "Vadims Podans [MVP]" <vpodans> wrote:

    >> gc servers | ?{$_ -notmatch "^#"}
    >> --
    >> WBR, Vadims Podans
    >> MVP: PowerShell
    >> PowerShell blog -www.sysadmins.lv
    >>
    >> <techsta...@xxxxxx> rakstija zinojuma
    >> "news:a852e49f-3c62-4dc2-b41c-9c3d0587ffad@xxxxxx"...
    >>
    >>
    >>

    >> > I have below file called servers.txt
    >> > --------------------------------------------------------
    >> > #Hostnames should be lower caps
    >> > Server1
    >> > Server2
    >> > Server3
    >> > #Server4
    >> > Server5
    >> > ----------------------------------------------------------
    >> > I would like to put some comment in the text file which powershell
    >> > should skip it. is it possible. e.g. I do not want powershell to read
    >> > anything which starts with #
    >>

    >> > Thank you in Advance
    >
    > Again thank you very much. Problem solved.
    > Do I know what ^ does ?
    >

      My System SpecsSystem Spec

  6. #6


    Umesh Thakur Guest

    Re: How to Skip comment in text - GC file.txt

    alternatively,
    gc servers | Where-Object {$_.StartsWith("#") -eq $false}

    should work too

    --
    Umesh

    "Old programmers never die. They just terminate and stay resident."



    "Vadims Podans [MVP]" wrote:

    > ^ means that pattern must match at string begining.
    > --
    > WBR, Vadims Podans
    > MVP: PowerShell
    > PowerShell blog - www.sysadmins.lv
    >
    > <techstarts@xxxxxx> rakstija zinojuma
    > "news:96452047-f04c-48a8-a198-4a5d8c0900f8@xxxxxx"...

    > > On Jun 4, 3:04 pm, "Vadims Podans [MVP]" <vpodans> wrote:

    > >> gc servers | ?{$_ -notmatch "^#"}
    > >> --
    > >> WBR, Vadims Podans
    > >> MVP: PowerShell
    > >> PowerShell blog -www.sysadmins.lv
    > >>
    > >> <techsta...@xxxxxx> rakstija zinojuma
    > >> "news:a852e49f-3c62-4dc2-b41c-9c3d0587ffad@xxxxxx"...
    > >>
    > >>
    > >>
    > >> > I have below file called servers.txt
    > >> > --------------------------------------------------------
    > >> > #Hostnames should be lower caps
    > >> > Server1
    > >> > Server2
    > >> > Server3
    > >> > #Server4
    > >> > Server5
    > >> > ----------------------------------------------------------
    > >> > I would like to put some comment in the text file which powershell
    > >> > should skip it. is it possible. e.g. I do not want powershell to read
    > >> > anything which starts with #
    > >>
    > >> > Thank you in Advance
    > >
    > > Again thank you very much. Problem solved.
    > > Do I know what ^ does ?
    > >
    >

      My System SpecsSystem Spec

  7. #7


    OldDog Guest

    Re: How to Skip comment in text - GC file.txt

    On Jun 5, 8:36*am, Matthias Tacke <Matth...@xxxxxx> wrote:

    > techsta...@xxxxxx wrote:

    > > Again thank you very much. Problem solved.
    > > Do I know what ^ does ?
    >
    > You should.
    > At least after having read:
    > * *get-help about_regular_expressions
    > or the online version
    > * *http://go.microsoft.com/fwlink/?LinkId=133231
    >
    > Regards
    > Matthias
    ^ Matches the beginning "book" -match "^bo"
    characters

    And it's get-help about_regular_expression ' No s at the end.

      My System SpecsSystem Spec

  8. #8


    Josh Einstein Guest

    Re: How to Skip comment in text - GC file.txt

    I figured I'd mention you could do it in one command with select-string...

    select-string '^(?!#)' file.txt

    <techstarts@xxxxxx> wrote in message
    news:a852e49f-3c62-4dc2-b41c-9c3d0587ffad@xxxxxx

    > I have below file called servers.txt
    > --------------------------------------------------------
    > #Hostnames should be lower caps
    > Server1
    > Server2
    > Server3
    > #Server4
    > Server5
    > ----------------------------------------------------------
    > I would like to put some comment in the text file which powershell
    > should skip it. is it possible. e.g. I do not want powershell to read
    > anything which starts with #
    >
    > Thank you in Advance

      My System SpecsSystem Spec

  9. #9


    Matthias Tacke Guest

    Re: How to Skip comment in text - GC file.txt

    OldDog wrote:

    > On Jun 5, 8:36 am, Matthias Tacke <Matth...@xxxxxx> wrote:

    >> get-help about_regular_expressions

    > And it's get-help about_regular_expression ' No s at the end.
    Well to be unambiguous
    get-help about_reg
    is sufficient,
    but PowerShell V2 from Windows 7 where I copied the whole line from has the
    s at the end.

    Regards
    Matthias

      My System SpecsSystem Spec

How to Skip comment in text - GC file.txt

Similar Threads
Thread Forum
compare two text files and report differences in a text file format
I thought that perhaps that Compare-Object could be used as the basis of a script that takes two text files and creates a text file documenting...
PowerShell
Convert hostname text file to IP text file
I'm trying to convert a list of servers names from hostnames to IP addresses. Can someone tell me whats wrong with my script? thanks Const...
VB Script
Append text to top of text file?
Hi, Anyone know how to append some text, to the top of a text file? I already know how to put it to the bottom using 'add-conent' ...
PowerShell
Read a line from a text file, without loading the entire file inmemory
I'm currently updating a function to generate password function create-password { $leet = @{e=3;o=0;l=1;a=4;i='!';t=7} $paddingchars =...
PowerShell
Looping Through A Text File To Find Patterns From Another Text Fil
Looping Through A Text File To Find Patterns From Another Text File All, I'm trying to loop through a text file searching for specific terms (a...
PowerShell
Howto: Add lines of text from a specific point in a text file..
Hi all, I wonder if you can help me... I have been doing allot of manual updates to ini files that i am using and would like to make things a...
VB Script
How do I read a text file and sort text by fixed positions?
I need to read the content of a file and sort the content by fixed width. Example file: sample_data.txt 23abdc1133cdde 14zzwd0034kkhe...
PowerShell