Select host names from log files

  • A+
Category:Languages

I have an application that generates 100's of text log files which are like

DaemonReruns=2|  Phase=|  Log=false| DS=LOG_4| Schema=LOLYY| DBMS=mssql| Host=abc.XYz.com| IDs=xxxxx,xxxx 

I need to select Host from these I tried

GC  C:/log_5.txt |     Select-String -Pattern 'Host=/"([^/"]*)/"' 

Gives no results, any help ?

 


There aren't any quotes in your example input. Try this regex:

get-content C:/log_5.txt | foreach {     if ($_ -match 'Host=([^|]+)') {         $Matches.1     } } 

Note: This actually returns the host names, not just the line.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: