Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Finding exactly four numbers

$
0
0

Hello all,

 

       I have a CSV file that I want to find exactly four numbers.  I do not want any numbers with any more or less than four numbers.  I also do not want four numbers attached to any letters either.

The code that I have is:

$input_path = ‘c:\Users\c011568\Desktop\Book1.csv’
$output_file = ‘c:\Users\c011568\Desktop\New_Book1.csv’
$regex = ‘\b\d{1,4}\b’
select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file

I almost does what I want.  It puts all numbers in a separate line, which is good, but there are extra numbers that I do not want.

Any ideas?


Viewing all articles
Browse latest Browse all 8583

Trending Articles