Solved

Powershell question about a text file

Posted on 2016-11-23
10
17 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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
'\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
Comment Utility
Perfect answer and quick respons
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 6

Author Comment

by:Danny Kon
Comment Utility
But how the command knows you want the last number
0
 
LVL 82

Expert Comment

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

Author Comment

by:Danny Kon
Comment Utility
Last question and if i wanted the 70, 70, 10, 10 third number from the right
0
 
LVL 82

Expert Comment

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

Author Comment

by:Danny Kon
Comment Utility
:)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now