Solved

Powershell question about a text file

Posted on 2016-11-23
10
26 Views
Last Modified: 2016-11-23
I have a text file with

Verkoper: JEAN-PAUL Leverdatum 7-11-2016
Nr. Omschrijving Aantal Stukprijs Verp.bel Bedr.incl.verp.
21051 Coca Cola Krat 24x20 cl 70 7,80 546,00
60547 Emballage Euro 5,00 70 5,00 350,00
22005 Coca Cola Light Krat 24x20 cl 10 8,20 82,00
60547 Emballage Euro 5,00 10 5,00 50,00

Wat is the best way to get only the last numbers and to add up so i need 546+350+82+50=1028

Thanks Danny
0
Comment
Question by:Danny Kon
  • 6
  • 4
10 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41899420
With a regular expression, for example:
$Amount = 0
Get-Content C:\Temp\Verkoper.txt | Where-Object {$_ -match '\s(?<Amount>\d+,\d\d)\s*\Z'} | ForEach-Object {$Amount += $Matches['Amount'].Replace(',', '.')}
$Amount

Open in new window

0
 
LVL 6

Author Comment

by:Danny Kon
ID: 41899440
I am happy i finally can help you learning some dutch now :)
I can not give you bonus points but can you maybe explain how this work

Thanks Danny
0
 
LVL 6

Author Comment

by:Danny Kon
ID: 41899452
oBdA

Because i think the question is to big i try to split the question in parts  but if you have maybe the time could you look at question

https://www.experts-exchange.com/questions/28984972/Powershell-to-extract-the-important-data-and-calculate-if-the-amounts-are-correct.html

Thanks again Danny
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 84

Expert Comment

by:oBdA
ID: 41899463
'\s(?<Amount>\d+,\d\d)\s*\Z' checks if the line matches
\s - a space, followed by
\d+ - at least one digit (more OK), followed by
, - a comma, followed by
\d\d - exactly two digits, followed by
\s* - any number of spaces (zero OK), followed by
\Z - end of string.
The (<Amount>...) is a named capturing group that captures the amount in question, without the unnecessary stuff around it.
If a match is found, the $Matches variable will contain a key 'Amount' with the captured content.
0
 
LVL 6

Author Closing Comment

by:Danny Kon
ID: 41899693
Perfect answer and quick respons
0
 
LVL 6

Author Comment

by:Danny Kon
ID: 41899714
But how the command knows you want the last number
0
 
LVL 84

Expert Comment

by:oBdA
ID: 41899719
Because the "\Z" at the end "anchors" the expression to the string's end.
0
 
LVL 6

Author Comment

by:Danny Kon
ID: 41899726
Last question and if i wanted the 70, 70, 10, 10 third number from the right
0
 
LVL 84

Expert Comment

by:oBdA
ID: 41899754
Yes, I'll have a look at your other question ...
0
 
LVL 6

Author Comment

by:Danny Kon
ID: 41899945
:)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DFS issue 3 26
Want to Create New-GlobalAddressList 2 13
rename several files on a directory 2 13
Is there a way to add all users in specific OU in a specific AD group? 8 47
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

827 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