-1

Good afternoon BASH. How can I find the line between the word Address and the word Parameters in the command output:

Address 2001:0:284a:364:3869:30e6:4fc4:c8f8 Parameters
---------------------------------------------------------
Interface Luid : Teredo Tunneling Pseudo-Interface
Scope Id : 0.0
Actual lifetime : infinite
Preferred lifetime : infinite
DAD state : Preferred
Address Type : Public
Skip as source : false

Address fe80::3869:30e6:4fc4:c8f8%11 Parameters
---------------------------------------------------------
Interface Luid : Teredo Tunneling Pseudo-Interface
Scope Id : 0.11
Actual lifetime : infinite
Preferred lifetime : infinite
DAD state : Preferred
Address Type : Other
Skip as source : false
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • 4
    Welcome to Stack Overflow. [SO is a question and answer page for professional and enthusiast programmers](https://stackoverflow.com/tour). Please add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself. – Zilog80 Jun 13 '21 at 13:19
  • 1
    Take a look at `sed`, `grep` or `awk`. – Cyrus Jun 13 '21 at 13:45

3 Answers3

1
$ sed -n 's/Address \(.*\) Parameters/\1/p' file
2001:0:284a:364:3869:30e6:4fc4:c8f8
fe80::3869:30e6:4fc4:c8f8%11
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
0

You can do it in two steps :

1- Find the lines where we have the word "Address" and the word "Parameters" : How to find lines containing a string in linux

grep 'Address.*Parameters' 

>>> Address 2001:0:284a:364:3869:30e6:4fc4:c8f8 Parameters
>>> Address fe80::3869:30e6:4fc4:c8f8%11 Parameters

2- Extract the string between the two words : How to use sed/grep to extract text between two words?

sed -e 's/Address\(.*\)Parameters/\1/'

>>> 2001:0:284a:364:3869:30e6:4fc4:c8f8 
>>> fe80::3869:30e6:4fc4:c8f8%11 

3 - Voila !!!

  • You never need both grep and sed. If it's trivial you can do whatever it is in sed alone and if it's not then you're better off doing it in awk alone. – Ed Morton Jun 13 '21 at 19:43
  • Thank you for the reminder sir @EdMorton. I was trying to adopt a pedagogical attitude by using different basic cases. But I could have improved the reflexion. – Franck Might Jun 13 '21 at 20:28
0

This answer, unlike those currently submitted, assumes, (based upon your other two tags, and ), that your tag, is supposed to be .

It also makes a best guess at the initial command used to wite the output you've submitted, so that it can do it all in one go.

@Echo Off
SetLocal EnableExtensions
(Set LF=^
% 0x0A %
)
For /F %%G In ('Copy /Z "%~f0" NUL') Do Set "CR=%%G"
For /F "Delims=" %%G In ('%SystemRoot%\System32\cmd.exe /V/D/C
 "%SystemRoot%\System32\netsh.exe interface ipv6 show addresses interface="Teredo Tunneling Pseudo-Interface" level=verbose | %SystemRoot%\System32\findstr.exe /RC:".*!CR!!LF!----" 2>NUL"
') Do For %%H In (%%G) Do Set /P "=%%H" 0<NUL | %SystemRoot%\System32\find.exe ":"
Pause

Expected output:

2001:0:284a:364:3869:30e6:4fc4:c8f8
fe80::3869:30e6:4fc4:c8f8%11
Press any key to continue . . . 
Compo
  • 36,585
  • 5
  • 27
  • 39