Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

REgex to find IP address then return a different column

$
0
0

Hi,

I've written this script to find IP addresses inside a text file - it uses Regex

$input_path = ‘2013-06-19-SyslogCatchAll.txt’
$output_file = ‘ip_addresses.txt’
$regex = ‘\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b’
select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file

The reason I needed to use Regex was because the IP address is surrounded by other text and it's not just in 1 column.  This works fine

Also in the text file in colum 1 is a time\date.  Is there  a way to say, foir each instance of the IP address return the column 1 data which is in the same row as the IP address?

Thanks


Alter De Ruine


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>