?
Solved

Modification to current Powershell script to produce desired output.

Posted on 2014-09-18
1
Medium Priority
?
148 Views
Last Modified: 2014-09-19
This is a continuation of the assistance I have been receiving today.

Another source file has the following structure in the PO1 and PID.

PO1**10*CA*10.61**UA*123456789456*IN*14524578*VN*45678~
CTP*ST*PQR*11.00~
PID*F*08***DESCRIPTION~

This basic structure is repeated in the file..

Sample Script:

$InputFile = "C:\original.txt"
$OutputFile = "C:\New.txt"

Function ParseText ($OutputFile,$InputFile){
Begin{
            $line,$poline,$totline,$total,$i = $null,$null,$null,$null,0
            Set-Content $OutputFile $null
            $Data = Get-Content -Path $InputFile | ?{$_ -match "(SA\*)|(PID\*)|(PO1\*{2})|(EFG\*)"}
      }
Process{
      $Data | % {
      #Check the end of data set
            If ($_ -match "EFG\*"){
                  If($poline -ne $null -and $total -ne $null){
                        $Totline = "Total: `$$Total"
                        Write-host "This is Total `$$total"
                        #Write the data collection to output file
                        "$poline$line`r`n$totline`r`n" | out-file $OutputFile -Encoding UTF8 -Append
                        #reset the variables
                        $line,$poline,$totline,$total,$i = $null,$null,$null,$null,0
                  }
            }
            #Collect the PO Number
            If($_ -match "(SA\*)(\d{0,10})"){
                  $poline = "PONumber: $($Matches[2])"
            }
            #Collect PO1 details and following PID Discription
            If($_ -match "(PO1\*{2})(\d{1,})\*(\w{1,})\*(\d{1,}(\.\d{1,})?)\*{2}(\w{1,})\*(\d{1,})"){
                  $i++
                  $total += [double]$Matches[2] * [double]$Matches[4]
                  $Desc = ($Data[([Array]::IndexOf($Data,$_)+1)] -split "\*\*\*\*|~")[1]
                  [String[]]$line += "`r`nItem $i`: UPC: $($Matches[7]), Desc: $Desc, Qty: $($Matches[2]) Price  `$$($Matches[4])"
            }
      }
 }
}

If(Test-Path $InputFile){
 ParseText $OutputFile $InputFile
}


How can I modify any of today`s scripts in order to get the desired output?

Currently the script I am using is not showing anything for the description, everything else is calculated or shown.

Here is the output desired.

PONumber: 1234561111
  Item 1: UPC: 12345678912345, Desc: information here, Qty: 248 Price: $10.00
  Item 2: UPC: 23456789123452, Desc: information here, Qty: 329 Price: $1.00
  Item 3: UPC: 98765432198765, Desc: information here, Qty: 20 Price $2.00
  Total: $Calculated total

 PONumber: 1234568888
  Item 1: UPC: 12345678912345, Desc: information here, Qty: 250 Price: $10.00
  Item 2: UPC: 23456789123452, Desc: information here, Qty: 200 Price: $1.00
  Item 3: UPC: 98765432198765, Desc: information here, Qty: 100 Price $2.00
  Total: $Calculated total
0
Comment
Question by:100questions
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 40331451
Change line
$Desc = ($Data[([Array]::IndexOf($Data,$_)+1)] -split "\*\*\*\*|~")[1]

Open in new window

to
$Desc = ($Data[([Array]::IndexOf($Data,$_)+1)] -split "\*\d{1,}|\*{1,}|~" | ?{$_})[2]

Open in new window

0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question