06-24-2013
In a variety of tools from sed on up, your strategy must be to capture the lines starting with the header in a buffer until you find a next header or EOF, then if the first header is not to your liking, delete all but the second header line and return to get another line. In sed. this is /pattern/ match, b and : for loop, N to add another line to the buffer, $ to test EOF. The last group is irregular as it has no second header line. You might h the line, remove the second header if any, decide if it is a keeper, and the g the original buffer back. You might add a dummy final header to stdin using "( cat file ; echo dummy )|sed", but of course you need to remove it. You can d or "s/...//" what you dislike or "sed -n" and p what you like, but remember there is a second header in the buffer!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a file which contains blocks of text - each block is a multi-lines text delimited by blank lines eg.
<blank line>
several lines of text
...
pattern found on this line
several more lines of text
...
<blank line>
How do you delete the block of text (including the blank lines) when... (17 Replies)
Discussion started by: gleu
17 Replies
2. Shell Programming and Scripting
Hi,
I have two files viz,
rak1:
$ cat rak1
rak2:
$ cat rak2
sdiff rak1 rak2 returns:
I want the lines that got modified, changed, or deleted preceding with the section they are in.
I have done this so far: (1 Reply)
Discussion started by: rakeshou
1 Replies
3. Shell Programming and Scripting
I want to change a line like
CPM_THRESHOLD 0.8 //
to a new value using sed
I am trying
sed -i "s/CPM_THRESHOLD/CPM_THRESHOLD\t$COH\t\t\/\//" $INPUT_4
but how can i substitute the whole line begining with CPM_THRESHOLD and substitute it? (2 Replies)
Discussion started by: larne
2 Replies
4. Shell Programming and Scripting
Hi All,
I have a file say abc.xml. In this file, I need to search for a pattern “SAP_GATEWAY_HOST”; if this pattern found and the next line also contain the pattern “nwprc03.cos” then I need to replace this pattern “nwprc03.cos” with some other pattern “nwdrc03.apjp”.
$ cat abc.xml... (3 Replies)
Discussion started by: Ritesh.patni84
3 Replies
5. Shell Programming and Scripting
I am trying to do some thing like this ..
In a file , if pattern found insert new pattern at the begining of the line containing the pattern.
example:
in a file I have this.
gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin
if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies
6. Shell Programming and Scripting
I thought that this was going to be quit simple using sed but i wasn't able to find a way to delete the second line of a text file if my pattern was not found in the line
With awk i am completly useless :rolleyes:
Any ideas? (2 Replies)
Discussion started by: jepeto
2 Replies
7. Shell Programming and Scripting
Hi,
suppose i have a txt file containing thye following data
2012156|sb3|nwknjps|BAYONNE|NJ|tcg
201221|094|mtnnjprc:HACKENSACK|NJ|tcg
201222|wn3|mtnnjtc|HACKENSACK|NJ|tcg
2018164|ik4|mtnntc|JERSEY CITY|NJ|tcg
20123482|ik4|mtnnjpritc,JERSEY CITY|NJ|tcg... (3 Replies)
Discussion started by: priyanka3006
3 Replies
8. UNIX for Dummies Questions & Answers
Hi,
I have a file with the following content:
---------
a 3242 tc_5 gdfg4
random text
a 3242 tc_6 gdfg4
random text
a 3242 tc_7 gdfg4
random text
a 3242 tc_4 gdfg4
---------
I want to replace the lines containing tc_? (tc_5, tc_6 etc. even with unknown numbers) with the found... (5 Replies)
Discussion started by: joas
5 Replies
9. Shell Programming and Scripting
Hello!. I am working on a very simple program and I have been trying different things. This is so far what I have done and there is one small detail that still does not work. It finds all the records in a phonebook per say:
./rem Susan
More than one match; Please select the one to remove: ... (3 Replies)
Discussion started by: bartsimpsong
3 Replies
10. Shell Programming and Scripting
hi,
i have /etc/inittab, I want to add another line after that when i find a pattern "l6:6:wait:/etc/rc.d/rc 6".
original
l6:6:wait:/etc/rc.d/rc 6
after-change
l6:6:wait:/etc/rc.d/rc 6
/sbin/if-pp-to-cng (3 Replies)
Discussion started by: learnbash
3 Replies
LEARN ABOUT HPUX
inet6_rth_reverse
inet6_rth_space(3N) inet6_rth_space(3N)
NAME
inet6_rth_add(), inet6_rth_getaddr(), inet6_rth_init(), inet6_rth_reverse(), inet6_rth_segments(), inet6_rth_space() - IPv6 Routing header
options manipulation functions.
SYNOPSIS
DESCRIPTION
These functions can be used by an application to build and examine an IPv6 Routing header. The Routing header can be used by an IPv6
source to list one or more intermediate nodes to be visited on the way to a packet's destination.
These three functions build a Routing header: returns the number of bytes required for a Routing header.
initializes the buffer data for a Routing header.
adds one IPv6 address to the Routing header.
Three functions deal with a returned Routing header: reverses a Routing header.
returns the number of segments in a Routing header.
fetches one address from a Routing header.
These functions are described below:
This function returns the number of bytes required to hold a routing
header of the specified type containing the specified number of segments (addresses). For an IPv6 Type 0 Routing header, the number
of segments must be between 0 and 127, inclusive. The return value is just the space for the Routing header. When the application
uses ancillary data, it must pass the returned length to to determine how much memory is needed for the ancillary data object (includ-
ing the structure).
If the return value is 0, then either the type of the Routing header is not supported by this implementation or the number of segments
is invalid for this type of Routing header.
This function returns the size but does not allocate the space required for the ancillary data.
Note: If type is 2 (Routing Header Type 2), segments must be 1 (RFC 4584).
This function initializes the buffer pointed to by
bp to contain a Routing header of the specified type. bp_len is only used to verify if the buffer is large enough.
The caller must allocate the buffer, and its size can be determined by calling
Upon success, the return value is the pointer to the buffer (bp), and the pointer is then used as the first argument to the function.
Upon an error, the return value is NULL.
Note: If type is 2 (Routing Header Type 2), segments must be 1 (RFC 4584).
This function adds the IPv6 address pointed to by
addr to the end of the Routing header being constructed.
If successful, the member of the Routing header is updated to account for the new address in the Routing header and the return value
of the function is 0. Upon an error the return value of the function is -1.
Note: If the Routing header is type 2, this function can only be called once.
This function takes a Routing header extension header pointed to by
the first argument in and writes a new Routing header. The new Routing header sends datagrams along the reverse of that route. The
function reverses the order of the addresses and sets the member in the new routing header to the number of segments. Both arguments
are allowed to point to the same buffer (that is, the reversal can occur in place).
The return value of the function is 0 on success, or -1 upon an error.
Note: If Routing header is type 2, this function returns -1 (RFC 4584).
This function returns the number of segments (addresses) contained in
the Routing header described by bp which can be 0 or greater.
The return value of the function is -1 upon an error.
This function returns a pointer to the IPv6 address specified by
index (which must be a value between 0 and one less than the value returned by in the Routing header described by bp.
An application should first call to obtain the number of segments in the Routing header.
Upon an error, the return value of the function is NULL.
Note: If Routing header is type 2, this function returns a pointer to the IPv6 home address specified by the ip6r2_homeaddr field in
which is pointed by bp. The index must be zero.
Notes
To use these functions, the application must be compiled with:
To receive a Routing header, the application must enable the socket option:
To send a Routing header, the application specifies it either as ancillary data in a call to or using (see send(2) and getsockopt(2),
respectively).
EXAMPLES
gives a comprehensive example in Appendix B.
SEE ALSO
send(2), getsockopt(2), IPv6(7P), xopen_networking(7).
inet6_rth_space(3N)