1

I am reading a text file where I need to filter out and perform some formatting if a row starts in a string and ends in a number. If i had known/fix values, I could use StartWith or EndsWith to filter this line. I tried using it as below but I guess that's wrong as it didn't work.

if(($record.StartsWith.GetType() -eq [string]) -and  ($record.EndsWith.GetType() -eq [int]))

Example: My rows read

TransDate,Merchant,Amount
Doe,Jane, *6098
3/4/2020,Walmart,6.45
3/4/2020,Starbucks,14.45
Doe,John, *6096
3/4/2020,Amazon,34.45

I need to be identify that row 2 and 5 have my card numbers. How can I identify these in powershell? Let me know please. Thanks

iRon
  • 20,463
  • 10
  • 53
  • 79
Raheel R
  • 19
  • 4

1 Answers1

1

You could use regex to identify the rows you're after ... a simple version could look like this:

$Content = Get-Content D:\sample\TextFile.txt
foreach($record in $Content){
    if($record -match '^[a-z].*\d$'){
        $record
    }
}
Olaf
  • 4,690
  • 2
  • 15
  • 23