Sponsored Content
Top Forums Shell Programming and Scripting Using sed to extract line of a file Post 303034864 by popeye on Wednesday 8th of May 2019 09:00:34 AM
Old 05-08-2019
Using sed to extract line of a file

Ok .. This is driving me nuts. I suppose I need another set of eyes.

Example Data
Code:
interface Vlan1
 description xxxxxxxxxxxx
 ip address 192.168.1.1 255.255.255.252
 no ip redirects
 no ip proxy-arp
 ip flow ingress
 ip pim sparse-mode
 load-interval 30
!
interface Vlan2
 description xxxxxxxxxxxx
 ip address 192.168.120.106 255.255.255.252
 no ip redirects
 no ip proxy-arp
 ip flow ingress
 ip pim sparse-mode
 load-interval 30
!
interface Vlan3
 description xxxxxxxxxxxx
 ip address 192.168.201.3 255.255.255.0
 ip helper-address 192.168.228.188
 ip helper-address 192.168.97.199
 ip helper-address 192.168.133.140
 ip helper-address 192.168.152.194
 no ip redirects
 no ip proxy-arp
 ip pim sparse-mode
 standby 0 ip 192.168.201.1
 standby 0 timers 1 3
 standby 0 authentication baronet2
!
interface Vlan4
 description xxxxxxxxxxxx
 ip address 192.168.120.110 255.255.255.252
 no ip redirects
 no ip proxy-arp
 ip flow ingress
 ip pim sparse-mode
 load-interval 30
!
interface Vlan5
 description xxxxxxxxxxxx
 ip address 192.168.202.3 255.255.255.0
 ip helper-address 192.168.228.188
 ip helper-address 192.168.97.199
 ip helper-address 192.168.133.140
 ip helper-address 192.168.152.194
 no ip redirects
 no ip proxy-arp
 ip pim sparse-mode
 standby 0 ip 192.168.202.1
 standby 0 timers 1 3
 standby 0 priority 105
 standby 0 preempt

The Results I am looking for is / are :

Interface and ip helper addresses associated with that interface

Code:
interface Vlan603
  ip helper-address 192.168.228.188
 ip helper-address 192.168.97.199
 ip helper-address 192.168.133.140
 ip helper-address 192.168.152.194
 

interface Vlan604
  ip helper-address 192.168.228.188
 ip helper-address 192.168.97.199
 ip helper-address 192.168.133.140
 ip helper-address 192.168.152.194
 etc 
 etc

I thought I solved this once before .. but lost some stuff in a new work laptop transition.

Any help would be appreciated.

POP
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract a line from a file using the line number

I have a shell script and want to assign a value to a variable. The value is the line exctrated from a file using the line number. The line number it is not fix, and could change any time. I have tried sed, awk, head .. See my script # Get randome line number from the file #selectedline = `awk... (1 Reply)
Discussion started by: zambo
1 Replies

2. Shell Programming and Scripting

extract file extension using sed

Hi, how can i extract file extension using sed? for e.g., if a file name is abc.txt then how can i get "txt" (after .) Thanks praveen (7 Replies)
Discussion started by: r_praveenk
7 Replies

3. Shell Programming and Scripting

extract a line from a file using the line number

Hello, I am having trouble extracting a specific line from a file when the line number is known. My first attempt involved grep -n 'hi' (the word 'hi will always be there) to get the line number before the line that I actually want (line 4). Extra Notes: -I am working in a bash script. -The... (7 Replies)
Discussion started by: grandtheftander
7 Replies

4. UNIX for Dummies Questions & Answers

Using sed to extract a substring at end of line

This is the line that I am using: sed 's/^*\({3}*$\)/\1 /' <test.txt >results.txt and suppose that test.txt contains the following lines: http://www.example.com/200904/AUS.txt http://www.example.com/200903/_RUS.txt http://www.example.com/200902/.FRA.txt What I expected to see in results.txt... (6 Replies)
Discussion started by: figaro
6 Replies

5. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

6. Shell Programming and Scripting

Extract a number from a line in a file and sed in another copied file

Dear all, I am trying to extract a number from a line in one file (task 1), duplicate another file (task 2) and replace all instances of the strings 300, in duplicated with the extracted number (task 3). Here is what I have tried so far: for ((k=1;k<4;k++)); do temp=`sed -n "${k}p"... (2 Replies)
Discussion started by: mnaqvi
2 Replies

7. Shell Programming and Scripting

extract a line from a file by line number

Hi guys, does anyone know how to extract(grep) a line from the file, if I know the line number? Thanks a lot. (9 Replies)
Discussion started by: aoussenko
9 Replies

8. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

9. Shell Programming and Scripting

sed or awk, cut, to extract specific data from line

Hi guys, I have been trying to do this, but... no luck so maybe you can help me. I have a line like this: Total Handled, Received, on queue Input Mgs: 140 / 14 => 0 I need to, get the number after the / until the =, to get only 14 . Any help is greatly appreciated. Thanks, (4 Replies)
Discussion started by: ocramas
4 Replies

10. Shell Programming and Scripting

Perl to extract information from a file line by line

In the below perl code I am using tags within each line to extract certain information. The tags that are used are: STB >0.8 is STRAND BIAS otherwise GOOD FDP is the second number GO towards the end of the line is read into an array and the value returned is outputed, in the first line that... (1 Reply)
Discussion started by: cmccabe
1 Replies
SUBST(1)						      General Commands Manual							  SUBST(1)

NAME
subst - substitute definitions into file(s) SYNOPSIS
subst [ -e editor ] -f substitutions victim ... DESCRIPTION
Subst makes substitutions into files, in a way that is suitable for customizing software to local conditions. Each victim file is altered according to the contents of the substitutions file. The substitutions file contains one line per substitution. A line consists of two fields separated by one or more tabs. The first field is the name of the substitution, the second is the value. Neither should contain the character `#', and use of text-editor metacharacters like `&' and `' is also unwise; the name in particular is best restricted to be alphanumeric. A line starting with `#' is a comment and is ignored. In the victims, each line on which a substitution is to be made (a target line) must be preceded by a prototype line. The prototype line should be delimited in such a way that it will be taken as a comment by whatever program processes the file later. The prototype line must contain a ``prototype'' of the target line bracketed by `=()<' and `>()='; everything else on the prototype line is ignored. Subst extracts the prototype, changes all instances of substitution names bracketed by `@<' and `>@' to their values, and then replaces the tar- get line with the result. OPTIONS
-e Substitutions are done using the sed(1) editor, which must be found in either the /bin or /usr/bin directories. To specify a dif- ferent executable, use the ``-e'' flag. EXAMPLE
If the substitutions file is FIRST 111 SECOND 222 and the victim file is x = 2; /* =()<y = @<FIRST>@ + @<SECOND>@;>()= */ y = 88 + 99; z = 5; then ``subst -f substitutions victim'' changes victim to: x = 2; /* =()<y = @<FIRST>@ + @<SECOND>@;>()= */ y = 111 + 222; z = 5; FILES
victimdir/substtmp.new new version being built victimdir/substtmp.old old version during renaming SEE ALSO
sed(1) DIAGNOSTICS
Complains and halts if it is unable to create its temporary files or if they already exist. HISTORY
Written at U of Toronto by Henry Spencer. Rich $alz added the ``-e'' flag July, 1991. BUGS
When creating a file to be substed, it's easy to forget to insert a dummy target line after a prototype line; if you forget, subst ends up deleting whichever line did in fact follow the prototype line. 25 Feb 1990 SUBST(1)
All times are GMT -4. The time now is 08:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy