Help with out-file command

Home Forums Scripting General Scripting Help with out-file command

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    tlewis0123
    Member
    #164767

    I have a script that I am developing. It reads a text file and generates output records for a new file.

    It is a text file and I am using substring function to check for records that I want (must start with “A ” and I know because the count is getting incremented correctly that it is correct in the flow…but no records…or actually what appears to only be one record, rather than the 396 that it is supposed to have…

    Here is the script… with some path info X’d out.

    $srcpath = “c:xxxxxxDocumentsprojectsNCOA”
    $destpath =”\xxxxxxxxDATA_ConNCOA updates”
    $filein = “cstacs01.txt”
    $fileout = “testout.txt”

    $myrecs = Get-Content ($srcpath + $filein)
    $i=0
    $outcnt = 0

    ForEach ($m in $myrecs)

    {
    $i++

    if ($check_a = $m.StartsWith(“A “)) {

    $addr1 = $m.substring(27,48 )
    $city = $m.Substring(75,28 )
    $st = $m.Substring(103,2)
    $zip = $m.Substring(106,5)
    $letter = $m.Substring(342,4)
    $debtor = $m.Substring(497,6)

    $outrec = “Debtor #” + $debtor + “-NCOA forwarded Address:” + $add1
    out-file -filepath ($srcpath + $fileout) -inputobject $outrec -force
    $outcnt++
    }
    }
    [/CODE]

    so the $outcnt variable is getting incremented to the correct count and I have stepped though in debug and see the variables are getting populated properly…

    but when I open the output file – I only have one record and it is incomplete. I am going to check but I also think it is not one that meets the “starts with” criteria

    Debtor #223892-NCOA forwarded Address:

    I am also posted an image of the screen which shows an excerpt of the variables[CODE]
    $srcpath = “c:xxxxxxDocumentsprojectsNCOA”
    $destpath =”\xxxxxxxxDATA_ConNCOA updates”
    $filein = “cstacs01.txt”
    $fileout = “testout.txt”

    $myrecs = Get-Content ($srcpath + $filein)
    $i=0
    $outcnt = 0

    ForEach ($m in $myrecs)

    {
    $i++

    if ($check_a = $m.StartsWith(“A “)) {

    $addr1 = $m.substring(27,48 )
    $city = $m.Substring(75,28 )
    $st = $m.Substring(103,2)
    $zip = $m.Substring(106,5)
    $letter = $m.Substring(342,4)
    $debtor = $m.Substring(497,6)

    $outrec = “Debtor #” + $debtor + “-NCOA forwarded Address:” + $add1
    out-file -filepath ($srcpath + $fileout) -inputobject $outrec -force
    $outcnt++
    }
    }
    [/CODE]

    so the $outcnt variable is getting incremented to the correct count and I have stepped though in debug and see the variables are getting populated properly…

    but when I open the output file – I only have one record and it is incomplete. I am going to check but I also think it is not one that meets the “starts with” criteria

    Debtor #223892-NCOA forwarded Address:

    I am also posted an image of the screen which shows an excerpt of the variables

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.