Sponsored Content
Top Forums Shell Programming and Scripting sed: find match and delete the line above Post 97716 by cstovall on Wednesday 1st of February 2006 04:56:57 PM
Old 02-01-2006
sed: find match and delete the line above

I am searching a dhcpd.conf to find the hardware ethernet match, then once the match is found delete just the line above it. For example:

testmachine.example {
hardware ethernet 00:00:00:00:00:00;
fixed address 192.168.1.100;
next-server 192.168.1.101;
filename "linux-install/pxelinux.0";
}

I would like to use sed to remove "testmachine.example {".
I was going to create a two step process by removing the line above the harware ethernet match. Then remove the hardware ethernet match through }. However, if someone knows how to find the harware ethernet match and remove the whole block, I would be very appreciative.

There are multiple fixed addresses in this file, so it can only remove this block based on the hardware ethernet match.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies

2. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

3. Shell Programming and Scripting

delete a line that does not match the pattern

hi, i am parsing a file, in that searching for lines those contains "$threadNo.Received message:" , if that line contains the required fields write them into a separate file other wise ignore them. i am using the following code,but it is printing all the lines , i dont want to rpint , please help... (3 Replies)
Discussion started by: Satyak
3 Replies

4. Shell Programming and Scripting

sed find matching pattern delete next line

trying to use sed in finding a matching pattern in a file then deleting the next line only .. pattern --> <ad-content> I tried this but it results are not what I wish sed '/<ad-content>/{N;d;}' akv.xml > akv5.xml ex, <Celebrant2First>Mickey</Celebrant2First> <ad-content> Minnie... (2 Replies)
Discussion started by: aveitas
2 Replies

5. Shell Programming and Scripting

sed to find pattern and delete line before and after

I have the following file: line1 line2 MATCH line3 line4 I need to find the pattern, "MATCH" and delete the line before and after MATCH. So the result should be line1 MATCH lline4 I have to use sed because it is the only utility that is common across my environments. I... (1 Reply)
Discussion started by: craftereric
1 Replies

6. 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

7. Shell Programming and Scripting

Delete line with match and previous line quoting/escaping problem

Hi folks, I've list of LDAP records in this format: cat cmmac.export.tmp2 dn: deviceId=0a92746a54tbmd34b05758900131136a506,ou=devices,ou=customer,ou=nl,o=upc cmmac: 00:13:11:36:a5:06 dn: deviceId=0a92746a62pbms4662299650015961cfa23,ou=devices,ou=customer,ou=nl,o=upc cmmac:... (4 Replies)
Discussion started by: tomas.polak
4 Replies

8. Shell Programming and Scripting

Sed find exact string and delete line with variable

All, I am trying to read in a variable and search a file then delete based on that string, but i want to match exact word. This works but it matches all, i don't want to match anthing that contains the string, just the exact string. sed -i "/$feedname/d" file I tried sed... (1 Reply)
Discussion started by: markdjones82
1 Replies

9. Shell Programming and Scripting

Delete the last line if match the string

Hi, How to delete the last line if is match the below string else no action... String checking "END OF FILE. ROW COUNT: " 9f680174-cb87-4f71-887a-93b6f62fa5aa|20077337254|2 9f680174-cb87-4f71-887a-93b6f62fa5aa|20077337254|0 229f680174-cb87-4f71-887a-93b6f62fa5aa|20077337254|3 END OF... (2 Replies)
Discussion started by: bmk
2 Replies

10. Shell Programming and Scripting

sed match exactly and delete

I am using following sed rule to delete 2 lines after a pattern match inclusive. # cat /tmp/temp.txt dns.com 11 22 mydns.com 11 22 dns.com.au 11 22 LAST LINE # cat /tmp/temp.txt | sed -e '/dns.com/,+2d' LAST LINE I just need to remove lines below dns.com only and NOT below... (5 Replies)
Discussion started by: anil510
5 Replies
dhcping(8)						      General Commands Manual							dhcping(8)

NAME
dhcping - send a DHCP request to DHCP server to see if it's up and running SYNOPSIS
dhcping [-v] [-q] [-i] [-r] -t maxwait -c client-IP-address -s server-IP-address -h client-hardware-address [-g gateway-IP-address] DESCRIPTION
This command allows the system administrator to check if a remote DHCP server is still functioning. Options are: -v Verbose, print some information. -V Very verbose, print a lot of information. -i Use DHCPINFORM packets. -r Use DHCPREQUEST packets (default behaviour). -q Quiet, print nothing on the screen. -t maxwait Maximum time to wait for an answer from the server in seconds. Default is 3 seconds. -c client-IP-address Request this IP address. Note that this is also the IP address the answer will be sent to. -s server-IP-address Send the DHCP packet to this IP address. -h client-hardware-address Use this hardware-address in the DHCP request. It can be up to sixteen octets separated by colons (i.e. 01:02:03:04) -g gateway-IP-address Use this IP address for the gateway IP address in the DHCP packet. This option is currently broken. RETURN VALUES
If everything goes okay, it returns 0. If there went something wrong, it returns 1. SETUP
This program should be installed setuid root or ran by root only. See SECURITY for more information. On your DHCP server, add these lines to the dhcpd.conf: host <your monitoring host FQDN> { hardware ethernet <your monitor host mac address>; fixed-address <your monitoring host IP address>; } Then try it: $ dhcping -c your monitoring host IP address -s your DHCP server IP address -h your monitor host mac address It will either respond with "no answer" or "Got answer from: your DHCP server IP address" The DHCP server logfile will give: DHCPREQUEST for 192.168.1.1 from 00:20:18:56:29:8f via ed0 DHCPACK on 192.168.1.1 to 00:20:18:56:29:8f via ed0 DHCPRELEASE of 192.168.1.1 from 00:20:18:56:29:8f via ed0 (found) Running in DHCPINFORM mode with -i: If you see "DHCPINFORM from 192.168.1.1 via xl0: not authoritative for subnet 192.168.1.0", you should add the authoritative statement to the subnet, See dhcpd.conf(5) for details. When running in very verbose mode, dhcping tries to dump all data of the send and received DHCP packets. It will first dump the packet in hex-format, then decodes the header and finally the options. HOW IT WORKS
The client either sends a DHCPREQUEST or DHCPINFORM packet to the server and waits for an answer. Then, if a DHCPREQUEST was send, it will send a DHCPRELEASE back to the server. SECURITY
This program is installed setuid root as it requires the privileges to bind itself to port 68 (bootpc). Root privileges are dropped as soon as the program has bound itself to that port. BUGS
Currently (this may, or may not, change in the future) the ISC DHCP daemon does not write leases with a fixed IP address in the dhcpd.leases file. DHCPINFORM packets can only be used on subnets the server is authoritative for. If the monitoring script runs on a subnet the server isn't authoritative for, it should use the DHCPREQUEST packets. I also experienced some problems with ISC DHCPD v2 servers, but that is also in the README of it. The -V option is still working, but shouldn't be used for debugging of the packets. Better use dhcpdump(8) for that, which is available on my website. I wanted to remove it, but decided only to do it from the documentation, not from the code. Maybe I'll need it one day for debugging. AUTHOR
Edwin Groothuis, edwin@mavetju.org (http://www.mavetju.org) SEE ALSO
dhcpd(8), dhclient(8), dhcpd.conf(5), dhcpdump(8) 3rd Berkeley Distribution January 27, 2002 dhcping(8)
All times are GMT -4. The time now is 10:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy