header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Stuck on If Statment reading a txt file
Last Post 03 Dec 2008 08:59 PM by danjphillips. 6 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
danjphillipsUser is Offline
New Member
New Member
Posts:15
Avatar

--
03 Dec 2008 08:00 PM  
What am I doing wrong here?  I'm basically looking at a txt file and reading each line to get a number value.  I then want to put that into an If statement checking if the value is Less Than what I tell it too.  Below is the code.

I have a txt file called c:\tsm-report.txt with the following data.

101
1000
27,409
554,547
554,983
555,355 6

==============================================

$tsmfailedbackupreport = "C:\tsm-report.txt"

$logreport = Get-Content $tsmfailedbackupreport

#This just shows me that I'm reading the txt file successfully
$logreport

foreach ($i in $logreport)

{

if ($i -lt "100") {Write-Host "Less Than 100"}

}

==============================================

This must be something stupid I'm doing.  I just don't see it.

Any ideas?
jschussUser is Offline
New Member
New Member
Posts:9
Avatar

--
03 Dec 2008 08:25 PM  
Looks like all of your strings are greater than 100.
Are you expecting 27, 409 as two values or one?
The last character 6 is that supposed to be part of 555,355 or a separate value?
danjphillipsUser is Offline
New Member
New Member
Posts:15
Avatar

--
03 Dec 2008 08:29 PM  
Oops, each one of the values is on a seperate line in the text file.  The comma is part of the single number, not two numbers.  I want to parse through that text file and write output for values less than 100.  It should report on 6 or others, but it doesn't.  Others meaning if I add more intergers to the text file.
EBGreenUser is Offline
New Member
New Member
Posts:61
Avatar

--
03 Dec 2008 08:35 PM  
So in the example that you posted, the 6 should be on it's own line?
danjphillipsUser is Offline
New Member
New Member
Posts:15
Avatar

--
03 Dec 2008 08:43 PM  
Correct each number should be on it's own line.  You can use anything.  I'm just trying to get it to work and show that items less than 100 are writing back output to the host.
EBGreenUser is Offline
New Member
New Member
Posts:61
Avatar

--
03 Dec 2008 08:50 PM  
See if this doesn't work for you:

$lines = get-content Test.txt
foreach ($line in $lines)
{
if ([int]$line -lt 100)
{
Write-host $line
}
}
danjphillipsUser is Offline
New Member
New Member
Posts:15
Avatar

--
03 Dec 2008 08:59 PM  

AWESOME!!  That [INT] did the trick.  Thanks again!!

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer