[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 52
  • Last Modified:

Powershell question about a text file

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
Danny Kon
Asked:
Danny Kon
  • 6
  • 4
1 Solution
 
oBdACommented:
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
 
Danny KonAuthor Commented:
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
 
Danny KonAuthor Commented:
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
Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

 
oBdACommented:
'\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
 
Danny KonAuthor Commented:
Perfect answer and quick respons
0
 
Danny KonAuthor Commented:
But how the command knows you want the last number
0
 
oBdACommented:
Because the "\Z" at the end "anchors" the expression to the string's end.
0
 
Danny KonAuthor Commented:
Last question and if i wanted the 70, 70, 10, 10 third number from the right
0
 
oBdACommented:
Yes, I'll have a look at your other question ...
0
 
Danny KonAuthor Commented:
:)
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now