• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Removing lines from a text file

R

RichS

#2
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 Computer

J
#3
> 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 Computer

J

Jacques Barathon [MS]

#4
"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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)