I would imagine something like:
"if a line containing ":" is followed by an empty line delete both lines (the line with ":" and the empty line)"
i.e. something like in general
if a line containing regex1 is followed (immediately after) by a line containing regex2 delete both lines.
if it would be on one line I would do: sed '/regex1.*regex2/d' -->
how to spread this command on 2 lines? And consider hat in my case regex2 is an empty line ( i.e. ^$).
Sorry, I posted my first reply based on a too cursory reading of your question.
Here's a brief explanation:
/:$/!b - if not a line ending with a colon, just skip to the end of the script and print.
N - this is a line ending with a colon; fetch the next line and glue them together.
/:\n$/d - if the combined two lines match this pattern, delete
else, print
The \n thing works differently in different versions of sed, but if it doesn't work, try with a literal newline, with or without a backslash.
Last edited by era; 09-18-2008 at 06:56 AM..
Reason: Note on \n in different versions of sed
Hi,
Test file x.txt below. This file is generated by a program that I unfortunately do not have control on how it gets presented/generated.
create PACKAGE "XXX_INTERFACE_DEFECT_RPT_TEST" is
TYPE refCursor IS REF CURSOR;
Function queryRecords (
p_status varchar2,
...
...
...
)... (4 Replies)
Hi guys I am trying to figure out how to match a pattern with a regex up to a full blank line. I will show you what I mean with this example:
example A
movie name: ted
movie name: TMNT
movie name: Jinxed
example B
movie names:
Gravity
Faster
Turbo
song titles:
dont
hello
problem (8 Replies)
Hello.
I have a config file (/etc/my_config_file) which may content :
#
# port for HTTP (descriptions, SOAP, media transfer) traffic
port=8200
# network interfaces to serve, comma delimited
network_interface=eth0
# set this to the directory you want scanned.
# * if have multiple... (6 Replies)
here is what i want to achieve.. i have a file with below contents
cat fileName
blah blah blah
.
.DROP this
REJECT that
.
--sport 7800 -j REJECT --reject-with icmp-port-unreachable
--dport 7800 -j REJECT --reject-with icmp-port-unreachable
.
.
.
more blah blah blah
--dport 3306... (14 Replies)
Hello,
I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance.
Contents of infile:
Test this 1...
Test this 2...
Test this 3... Test this 4... Test this... (2 Replies)
All,
I have a file which contains two entry with spaces (either one or more than one space). ex.
/tmp/scripts/sql CUST_YR_END_INI.sql
/tmp/scripts/sql CUST_WK_END_INI.sql
/tmp/scripts/sql CUST_MTH_END_INI.sql
/tmp/scripts/sql CUST_YR_END_INC.sql
now I want to... (11 Replies)
I've got a report I need to make easier to read Using sh on HP-UX 11.12.
In short, I want to search for a regular expression and when found, examine the next line to see if it's blank. If so, then delete both lines. If not blank, move on to the next regexp. Repeat.
So far I've got:
... (7 Replies)
I'm new to using sed and grep commands, but have found them extremely useful. However I am having a hard time figuring this one out:
Delete every line containing the word CEN and the next line as well.
ie. test.txt
blue
324 CEN
green
red
blue
324 CEN
green
red
blue
to produce:... (2 Replies)
I have a file which has the first blank line:
sundev22$cat /t1/bin/startallocs
/t1/bin/startallocsys 123
sundev22$
Is there a command to remove this first blank line? Thanks for help -A (4 Replies)