Solved

Powershell question about a text file

Posted on 2016-11-23
10
27 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 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
Industry Leaders: 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 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

733 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