Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell question about a text file

Posted on 2016-11-23
10
Medium Priority
?
40 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
[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
  • 6
  • 4
10 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

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 85

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 85

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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