Sponsored Content
Top Forums Shell Programming and Scripting sed: delete regex line and next line if blank Post 302237648 by one71 on Thursday 18th of September 2008 05:22:01 AM
Old 09-18-2008
sed: delete regex line and next line if blank

Hi,

I want to write a sed script which from

Code:
batiato:

batiato/giubbe:
pip_b.2.txt
pip_b.3.txt
pip_b.3mmm.txt

bennato:

bennato/peterpan:
123.txt

consoli:
pip_a.12.txt

daniele:

daniele/anna:
abc.txt

procuces

Code:
batiato/giubbe:
pip_b.2.txt
pip_b.3.txt
pip_b.3mmm.txt

bennato/peterpan:
123.txt

consoli:
pip_a.12.txt

daniele/anna:
abc.txt

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. ^$).

thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to delete a first blank line from the file

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)
Discussion started by: aoussenko
4 Replies

2. Shell Programming and Scripting

Delete last blank line.

I need to delete the last line only if its blank not otherwise. (3 Replies)
Discussion started by: dinjo_jo
3 Replies

3. Shell Programming and Scripting

Sed or Grep to delete line containing patter plus extra line

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)
Discussion started by: rocketman88
2 Replies

4. Shell Programming and Scripting

Need sed help: find regex and if the next next line is blank, delete both

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)
Discussion started by: Scottie1954
7 Replies

5. Shell Programming and Scripting

delete blank line from middle of a file

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)
Discussion started by: anshu ranjan
11 Replies

6. Shell Programming and Scripting

Find regex, place on individual lines and insert blank line before

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)
Discussion started by: deneuve01
2 Replies

7. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

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)
Discussion started by: vivek d r
14 Replies

8. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

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)
Discussion started by: jcdole
6 Replies

9. Shell Programming and Scripting

Regex to include up to blank line.

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)
Discussion started by: acoding
8 Replies

10. UNIX for Dummies Questions & Answers

How to delete blank line/s before and after a search pattern?

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)
Discussion started by: newbie_01
4 Replies
MAC-VENDOR(5)							File Formats Manual						     MAC-VENDOR(5)

NAME
mac-vendor - Ethernet vendor file for arp-scan SYNOPSIS
mac-vendor.txt DESCRIPTION
The mac-vendor.txt contains Ethernet MAC to vendor string mappings for arp-scan. It is used in addition to the IEEE OUI and IAB listings in ieee-oui.txt and ieee-iab.txt. It is for MAC-vendor mappings that are not covered by the IEEE manufacturer listings. Each line in the mac-vendor.txt file contains a MAC-vendor mapping in the form: <MAC-Prefix><TAB><Vendor> Where <MAC-Prefix> is the prefix of the MAC address in hex, and <Vendor> is the name of the vendor. The prefix can be of any length from two hex digits (one octet) to twelve hex digits (six octets, the entire Ethernet hardware address). The alphabetic hex characters [A-F] must be entered in upper case. For example: 012345 would match 01:23:45:xx:xx:xx, where xx represents any value; 0123456 would match 01:23:45:6x:xx:xx; and 01234567 would match 01:23:45:67:xx:xx. Blank lines and lines beginning with "#" are ignored. The order of entries in the file is not important. arp-scan will attempt to match larger prefixes before trying to match smaller ones, and will stop at the first match. FILES
/usr/local/share/arp-scan/mac-vendor.txt EXAMPLE
# From nmap Debian bug report #369681 dated 31 May 2006 525400 QEMU B0C420 Bochs # From RFC 2338: 00-00-5E-00-01-{VRID} 00005E0001 VRRP (last octet is VRID) # Microsoft WLBS (Windows NT Load Balancing Service) # http://www.microsoft.com/technet/prodtechnol/acs/reskit/acrkappb.mspx 02BF Microsoft WLBS (last four octets are IP address) AUTHOR
Roy Hills <Roy.Hills@nta-monitor.com> SEE ALSO
arp-scan(1) get-oui(1) get-iab(1) arp-fingerprint(1) http://www.nta-monitor.com/wiki/ The arp-scan wiki page. March 30, 2007 MAC-VENDOR(5)
All times are GMT -4. The time now is 09:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy