linux - BASH: grep/awk/sed to extract variable data -


UPDATE I need to make it clear that Jon8RFC-LT and DOMAIN are just normal for dynamic content Examples are such as IP address and MAC address; Retrieves nmblookup based on IP address and displays full dynamic content If awk is used, then I should have a way to draw 4 dynamic values ​​from nmblookup: IP, hostname / asset name, domain name, mac Address Sorry for the confusion, I updated the code to make it more clear.

I have been searching and using my Linux book for a few days and I do not know what I want awk / gawk / grep / examplerep / Sed (I think I have one or more of these I need to:

su_nmblookup = $ (nmblookup-A $ ipaddress)

which returns < / P>

  Warning: "idmap backend" option has been removed Added interface eth0 ip = a07d :: a07d: a07d: a07d: a07d% eth0 bcast = b57d :: ffff: ffff: Ffff: ffff% eth0 netmask = fff: ffff: Ffff: ffff :: added interface eth1 ip = b57d :: b57d: b57d: b57d: b57d% eth1 bcast = a07d :: ffff: ffff: ffff: ffff% eth1 netmask = ffff: ffff: ffff: ffff :: Added interface eth0 Ip = 234.234.234.234 bcast = 12.12.12.12 netmask = 255.255.0.0 socket opened. Given the status of 123.123.123.123, Zone 8 RFC-LT & lt; 00 & gt; - B & lt; ACTIVE & gt; DOMAIN & lt; 00 & gt; - & lt; Group & gt; B & lt; ACTIVE & gt; Joan 8 RFC-LT & LTF; 20> - B & lt; ACTIVE & gt; DOMAIN & lt; 1e & gt; - & lt; Group & gt; B & lt; ACTIVE & gt; MAC Address = 4F-A2-4F-A2-4F-A2  

The best I have managed, cutting it down with this code :

display = $ {su_nmblookup / # * looking / searching}
  Search for the status of 123.123.123.123 JON8RFC -LT & lt; 00 & gt; - B & lt; ACTIVE & gt; DOMAIN & lt; 00 & gt; - & lt; Group & gt; B & lt; ACTIVE & gt; Joan 8 RFC-LT & LTF; 20> - B & lt; ACTIVE & gt; DOMAIN & lt; 1e & gt; - & lt; Group & gt; B & lt; ACTIVE & gt; MAC address = 4F-A2-4F-2-4F-A2  

However, what do I want to know is that any of these clean formats How to do it again I would like to know that grep / awk / sed works with extracting data with these two instances, with one and only new lines to preserve formatting. I had a hell of a time, even getting quoted / coding to work properly due to formatting and GT / LT symbols!

  Viewing the status of 123.123.123.123, Zone 8 RFC-LT DOMAIN 4F-A2-4F-A2-4F-A2  

Or, just

  JON8RFC-LT DOMAIN 123.123.123.123 Thank you for your help!   

input.txt

      code = awk / / {print} / JON8RFC-LT / {If (a! = 1) {print "\ t" $ 1; A = 1}} / DOMAIN / {if (b! = 1) is searching for the status as {print "\ t" $ 1; B = 1}} / MAC address / {print "\ t" $ 4} "input.txt  

updated the regenerator suggested to be low :

  awk / / / {print} / JON8RFC-LT / & amp; ! One {print "\ t" $ 1; A = 1} / DOMAIN / & amp; Amp;   

Print "> <123>

  awk / /, / MAC address / {print; gateline, print "\ t" $ 1; gateline,     Print "\ t" $ 1; gateline; gateline; gateline; gateline; print "\ t" $ 4; exit 0} 'input.txt  

follows the lines on two lines Searching ... You want the first word then ignores three rows and then MAC addresses Micro print.


Comments

Popular posts from this blog

c# - Highlight all words containing a letter in a richtextbox -

Editing Python Class in Shell and SQLAlchemy -

java - JavaFX WebEngine Video Playback in Linux -