Operating System - Linux
1753835 Members
7585 Online
108806 Solutions
New Discussion юеВ

Re: How to extract ID and device file

 
SOLVED
Go to solution
Sandman!
Honored Contributor

Re: How to extract ID and device file

Did you try the awk construct I have posted? It does exactly what you're looking for viz., print the device ID followed by the device filename on the same line and it excludes the alternates.
Hein van den Heuvel
Honored Contributor

Re: How to extract ID and device file

Ah, you do want all and not just 'grep' for one. Try:

$ perl -nle '$dev=$1 if /^Logi.*\[(.*)\]/; if ($dev && /\s(c\d+t\S+)\s/) { print "$dev $1";$dev=""}
' devices.txt


$dev=$1 if /^Logi.*\[(.*)\]/; # remember stuff between box if line starts with 'Logi'
if ($dev && /\s(c\d+t\S+)\s/) # If we have a device and it looks like a 'ctd' on line
{ print "$dev $1";$dev=""} # print and clear device.


Hein.

IT_2007
Honored Contributor

Re: How to extract ID and device file

sandman,

Tried your method by simply copy and paste but didn't return anything.

awk '/device/{x=z[split(y[split($NF,y,"[")],z,"]")-1]};/active alive/{print x,$3;exit}' file1.out
IT_2007
Honored Contributor

Re: How to extract ID and device file

Thanks a bunch to James for simple solution - one liner!!!