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
smfi_addheader
smfi_addheader(3N) smfi_addheader(3N)
NAME
smfi_addheader() - adds a header to the current sendmail message
SYNOPSIS
PARAMETERS
includes the following arguments:
ctx Specifies the opaque context structure.
headerf Specifies the header name, which is a non-NULL, null- terminated string.
headerv Specifies the header value to be added. headerv is a non-NULL, null-terminated string and can be an empty string.
DESCRIPTION
adds a header to the current message. can be called only from the function.
Notes
does not change existing headers of a message. To change the current value of a header, use the routine.
A filter that calls the must set the flag in the structure passed to the
For the filter, the order in which filters are placed is important. Filters placed later in the sequence will observe the changes already
done by the earlier filters.
The name and the value of the header are not checked for standards compliance. However, each line of the header must be under 2048 charac-
ters. If longer headers are needed, multi-line header must be used. To make a multi-line header, insert a line feed (ASCII 0x0a, or
in
C) followed by at least one whitespace character, such as, a space (ASCII 0x20) or tab (ASCII 0x09, or in C). The line feed must not be
preceded by a carriage return (ASCII 0x0d); the MTA adds this automatically. It is the responsibility of the filter writer to ensure that
standards are not violated.
RETURN VALUE
returns due to the following reasons:
o The headerf or headerv is
o Adding headers in the current connection state is invalid.
o Memory allocation failure.
o Network error
o is not set when the routine is called.
returns on success.
EXAMPLES
Following is an example to add a header:
AUTHOR
was developed by the Sendmail Inc.
SEE ALSO
smfi_chgheader(3N), smfi_insheader(3N), smfi_addrcpt(3N), smfi_delrcpt(3N), smfi_replacebody(3N).
on
smfi_addheader(3N)