###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
###### Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
###### Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

# powershell HELP!! Reading file and separating text to seperate files

Powershell
I've been banging my head against the wall lately your help is greatly appreciated. I'm pretty new to powershell so chances are I don't have the methods/correct logic.

All i want to do is remove line feeds and carriage returns
It seems to be simple to add in line feeds with r n with the -replace cmd...
(gc c:\extract.txt) -replace "~",''rn" | sc c:\extract.txt - works
but
(gc c:\extract.txt) -replace "rn",'' " | sc c:\extract.txt - does not work

the end result I want to open a file find text "isa" copy isa and all text after it until it finds isa again and write each isa and text to a separate file for each isa it finds.

example

original file(c:\text.txt)
isa textline1
textline2
textline3
isa textline1
textline2
textline3
and etc...

end result

file1(c:\extract1.txt)
isa textline1
textline2
textline3

file2(c:\extract2.txt)
isa textline1
textline2
textline3

I've tried a couple of different ways but nothing seems to be working

here's the code!

$now=get-Date$yr=$now.Year.ToString()$mo=$now.Month.ToString()$dy=$now.Day.ToString()$hr=$now.Hour.ToString()$mi=$now.Minute.ToString() if ($mo.length -lt 2) {
$mo="0"+$mo #pad single digit months with leading zero
}
if ($dy.length -lt 2) {$dy="0"+$dy #pad single digit day with leading zero } if ($hr.length -lt 2) {
$hr="0"+$hr #pad single digit hour with leading zero
}
if ($mi.length -lt 2) {$mi="0"+$mi #pad single digit minute with leading zero }$currenttime = ($yr +$mo + $dy +$hr + $mi) function writefile([string]$txt) {
#echo "blah"
sleep -Seconds 1
$index =$index + 1
$textfile = "c:\$currenttime $index extract.txt" Add-Content$textfile $txt }$b = gc c:\test.txt | ForEach-Object{$_ -replace "rn",""}$b.Split( "ISA" )
writefile \$b