Windows Vista Forums

Removing lines from a text file

  1. #1


    Did Guest

    Removing lines from a text file

    Hi all,
    I want to remove line from txt file, exectly like i write line with
    out-file
    how can i do so ?

    Thanks


      My System SpecsSystem Spec

  2. #2


    RichS Guest

    RE: Removing lines from a text file

    I think you will need to read the file into PowerShell and check line by line
    for the file you want to remove - the rest of the file can be written back to
    a file
    --
    Richard Siddaway
    Please note that all scripts are supplied "as is" and with no warranty
    Blog: http://richardsiddaway.spaces.live.com/
    PowerShell User Group: http://www.get-psuguk.org.uk


    "Did" wrote:

    > Hi all,
    > I want to remove line from txt file, exectly like i write line with
    > out-file
    > how can i do so ?
    >
    > Thanks
    >
    >


      My System SpecsSystem Spec

  3. #3


    Jean Guest

    Re: Removing lines from a text file

    > Hi all,
    > I want to remove line from txt file, exectly like i write line with
    > out-file
    > how can i do so ?
    >
    > Thanks


    ie (remove the third line of u:\testfile.txt) :

    $f=${u:\testfile.txt}
    $f[2]=$null
    ${u:\testfile.txt}=$f

    Regards,

    --
    Jean - JMST
    Belgium



      My System SpecsSystem Spec

  4. #4


    Jacques Barathon [MS] Guest

    Re: Removing lines from a text file

    "Did" <didi10000@walla.co.il> wrote in message
    news:1173872693.838623.24650@d57g2000hsg.googlegroups.com...
    > Hi all,
    > I want to remove line from txt file, exectly like i write line with
    > out-file
    > how can i do so ?


    If you want to remove lines matching some specific text (e.g. "bouh"), you
    can write this:

    (type myfile.txt) -notmatch "bouh" | out-file mycleanfile.txt

    "bouh" can be any regular expression so you really have great control over
    your filter here.

    Hope that helps,
    Jacques


      My System SpecsSystem Spec


Removing lines from a text file
Similar Threads
Thread Forum
Using lines in a text file PowerShell
Howto: Add lines of text from a specific point in a text file.. VB Script
get the number of lines in a text file PowerShell
Removing lines from a text file by matching against substrings PowerShell
removing first three lines in a text file PowerShell