Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to sum a column

Status
Not open for further replies.

anil5555

Technical User
Aug 20, 2006
2
US
I have below script ...
param (
[Parameter(Mandatory)]
[String] $Path,
[decimal] $days
)
$text = get-content $path

(Get-Content $path).Replace("`t", " ") | set-content "C:\anil\input555.txt"
$path = "c:\anil\input555.txt"
$ErrorActionPreference = 'Stop'
$count=0
$data = Get-Content $path
$limit = (Get-Date).AddDays(-$days)
#$data[0] -replace ' +',"`t" # replace space with tab in first line
$data | Select-Object | % {
$null = $_ -match '^(/data/.+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+)'
$timestamp = [DateTimeOffset]::FromUnixTimeMilliseconds($Matches[2]/1000000).DateTime
if ($timestamp -lt $limit) {
$formattedTimestamp = Get-Date $timestamp -Format 'yyyy-MM-dd' $Matches[1],$formattedTimestamp,$Matches[3],$Matches[4],$Matches[5],$Matches[6],$Matches[7],$Matches[8],$Matches[9] -join "`t"
$count++
}

}
write-host "Number of Matches for more than $days days older: $count files"

Here i want total size in GB by adding all $Matches[4] WHERE they suffice "$timestamp -lt $limit". Another thing so $Matches[4] has value in bytes.
my output looks like
Number of Matches for more than 100 days older: 20000 files with toatal size xxxxxGB
 
Your code is a bit confusing. But if that is all that isn't working, try this:

Code:
param (
[Parameter(Mandatory)]
[String] $Path,
[decimal] $days
)
$text = get-content $path

(Get-Content $path).Replace("`t", " ") | set-content "C:\anil\input555.txt"
$path = "c:\anil\input555.txt"
$ErrorActionPreference = 'Stop'
$count=0
[COLOR=#EF2929][b]$byte_size = 0[/b][/color]
$data = Get-Content $path
$limit = (Get-Date).AddDays(-$days)
#$data[0] -replace ' +',"`t" # replace space with tab in first line
$data | Select-Object | % {
$null = $_ -match '^(/data/.+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+) +(\d+)'
$timestamp = [DateTimeOffset]::FromUnixTimeMilliseconds($Matches[2]/1000000).DateTime
if ($timestamp -lt $limit) {
$formattedTimestamp = Get-Date $timestamp -Format 'yyyy-MM-dd' $Matches[1],$formattedTimestamp,$Matches[3],$Matches[4],$Matches[5],$Matches[6],$Matches[7],$Matches[8],$Matches[9] -join "`t"
$count++
[COLOR=#EF2929][b]$byte_size = $byte_size + $Matches[4][/b][/color]
}

}
[COLOR=#EF2929][b]$gb_size = $byte_size/(1024*1024*024)[/b][/color]
write-host "Number of Matches for more than $days days older: $count files [COLOR=#EF2929][b]with a total size of $gb_size GB[/b][/color]"



Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top