Sponsored Content
Top Forums Shell Programming and Scripting SED: delete and print the only exact matched pattern Post 302212481 by new_buddy on Monday 7th of July 2008 05:19:42 PM
Old 07-07-2008
SED: delete and print the only exact matched pattern

I am really need help with the regular expression in SED. From input file, I need to extract lines that have the port number (sport or dport) as defined. The input file is something like this
Code:
time=1209515280-1209515340 dst=192.168.133.202 src=208.70.8.23  bytes=2472 proto=6  sport=80 dport=1447
time=1209515280-1209515340 dst=192.168.133.202 src=208.70.8.23  bytes=2526 proto=6  sport=80 dport=1811
time=1209515280-1209515340 dst=192.168.133.202 src=72.14.217.189  bytes=270 proto=6  sport=80 dport=3145
time=1209515280-1209515340 dst=192.168.133.202 src=78.136.25.50  bytes=610 proto=6  sport=80 dport=3158

How can I possibly define the pattern if I only want the exact pattern match. If I only wanted port 4501, is it correct the way I defined in the first line of the sed file below?
The example of patterns in file p2pport-delete.sed are here:
Code:
/port=[4][5][0][1]/d
/port=[4][6][6-7][1-4]/d
/port=[4][6][7][7]/d
.....

Apart from that, I need to have copy of those deleted lines in different file. I am using pattern/p instead. Here is file p2pport-print.sed
Code:
/port=[4][5][0][1]/p
/port=[4][6][6-7][1-4]/p
/port=[4][6][7][7]/p
.....

However, from the output, I found out that the total lines deleted from p2pport-delete.sed and printed from p2pport-print.sed is different. This assure that my sed file is wrong.
I hope that I could get help from anyone that could help me.
Many thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED: match pattern & delete matched lines

Hi all, I have the following data in a file x.csv: > ,this is some text here > ,,,,,,,,,,,,,,,,2006/11/16,0.23 > ,,,,,,,,,,,,,,,,2006/12/16,0.88 < ,,,,,,,,,,,,,,,,this shouldnt be deleted I need to use SED to match anything with a > in the line and delete that line, can someone help... (7 Replies)
Discussion started by: not4google
7 Replies

2. Shell Programming and Scripting

Sed to delete exactly match pattern and print them in other file

Hi there, I need help about using sed. Iam using sed to delete and print lines that match the port number as listed in sedfile. I am using -d and -p command for delete match port and print them respectively. However, the output is not synchonize where the total deleted lines is not similar with... (3 Replies)
Discussion started by: new_buddy
3 Replies

3. Shell Programming and Scripting

print last matched pattern using perl

Hi, If there exist multiple pattern in a file, how can I find the last record matching the pattern through perl. The below script searches for the pattern everywhere in an input file. #! /usr/bin/perl -s -wnl BEGIN { $pattern or warn"Usage: $0 -pattern='RE' \n" and exit 255;... (5 Replies)
Discussion started by: er_ashu
5 Replies

4. Shell Programming and Scripting

Print only matched pattern in perl

Hi, I have script like below: #!/usr/local/bin/perl use strict; use warnings; while (<DATA>) { ( my ($s_id) = /^\d+\|(\d+?)\|/ ) ; if ( $s_id == 1 ){ s/^(.*\|)*.*ABC\.pi=(+|+)*.*ABC\.id=(\d+|+).*$/$1$2|$3/s; print "$1$2|$3\n"; (2 Replies)
Discussion started by: sol_nov
2 Replies

5. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

6. Shell Programming and Scripting

Delete lines and the first pattern between 2 matched patterns

Hi, i need help to delete all the lines between 2 matched patterns and the first pattern must be deleted too. sample as follows: inputfile.txt >kump_1 ........................... ........................... >start_0124 dgfhghgfh fgfdgfh fdgfdh >kump_2 ............................. (7 Replies)
Discussion started by: redse171
7 Replies

7. Shell Programming and Scripting

Regex: print matched line and exact pattern match

Hi experts, I have a file with regexes which is used for automatic searches on several files (40+ GB). To do some postprocessing with the grep result I need the matching line as well as the match itself. I know that the latter could be achieved with grep's -o option. But I'm not aware of a... (2 Replies)
Discussion started by: stresing
2 Replies

8. UNIX for Advanced & Expert Users

To print from the first line until pattern is matched

Hi I want to print the line until pattern is matched. I am using below code: sed -n '1,/pattern / p' file It is working fine for me , but its not working for exact match. sed -n '1,/^LAC$/ p' file Input: LACC FEGHRA 0 LACC FACAF 0 LACC DARA 0 LACC TALAC 0 LAC ILACTC 0... (8 Replies)
Discussion started by: Abhisrajput
8 Replies

9. Shell Programming and Scripting

awk to delete content before and after a matched pattern

Hello, I have been trying to write a script where I could get awk to delete data before and after a matched pattern. For eg Raw data Start NAME = John Age = 35 Occupation = Programmer City = New York Certification Completed = No Salary = 80000 End Start NAME = Mary Age = 25... (2 Replies)
Discussion started by: sidnow
2 Replies

10. Shell Programming and Scripting

Issue with sed command does not replace exact string matched

I have a file change.sed more change.sed I fire the below command inorder to replace "190.169.11.15" with "10.4.112.240" in proxy.logsed -f change.sed proxy.log proxy.log has the below entry more proxy.log The command replaces both 190.169.11.15 & 190.169.11.155 as below: I am expecting... (17 Replies)
Discussion started by: mohtashims
17 Replies
DNET(8) 						    BSD System Manager's Manual 						   DNET(8)

NAME
dnet -- dumb networking library test program SYNOPSIS
dnet command args [...] DESCRIPTION
dnet is a simple test program for the dnet(3) library. It can be used to compose and transmit network datagrams as a Unix-style filter (e.g. reading from or writing to files and pipes) or modify the local system network configuration (including the ARP cache, firewall ruleset, net- work interfaces, and routing table). Payload generation commands addr address [...] Convert the address (specified as a hostname, IP address, or MAC address) into its binary representation on standard output. hex string [...] Convert the C-style escaped string (shellcode, for instance) into its binary representation on standard output. rand len Write len random bytes to standard output. Packet encapsulation commands eth [type type] [src mac] [dst mac] Prepend the data read from standard input with an Ethernet header on standard output. The Ethernet type may be specified as 'arp', 'ip', or as a hex, octal, or decimal number. arp [op op] [sha mac] [spa host] [tha mac] [tpa host] Prepend the data read from standard input with an ARP header on standard output. The ARP op may be specified as 'req', 'rep', 'revreq', 'revrep', or as a hex, octal, or decimal number. ip [tos num] [id num] [off offset] [ttl num] [proto protocol] [src host] [dst dst] Prepend the data read from standard input with an IP header on standard output. The fragmentation offset may be specified as a decimal number (optionally concatenated with '+' to indicate more fragments) or as a hex number. The protocol may be specified by name, or as a hex, octal, or decimal number. icmp [type num] [code num] Prepend the data read from standard input with an ICMP header on standard output. tcp [sport port] [dport port] [flags flags] [seq num] [ack num] [win num] [urp num] Prepend the data read from standard input with a TCP header on standard output. A port may be specified by name or hex, octal, or deci- mal number. The TCP flags may be specified as some combination of the characters in the set 'SAFRPU' or as a hex number. udp [sport port] [dport port] Prepend the data read from standard input with a UDP header on standard output. A port may be specified by name or hex, octal, or deci- mal number. Packet transmission commands send [device] Read a packet from standard input and send it over the network. If no device is specified, the packet is assumed to be an IP datagram and routed to its destination. Otherwise, the packet is assumed to be an Ethernet frame and is transmitted on the specified interface. Kernel interface commands arp show Display the kernel ARP cache. arp get host Display the kernel ARP entry for host. arp add host mac Add an ARP entry mapping the mac address for host. arp delete host Delete the ARP entry for host. fw show Display the kernel firewall ruleset. fw add|delete action direction device protocol src[:port[-max]] dst[:port[-max]] [type[/code]] Add a rule to or delete a rule from the active firewall ruleset. The action must be either 'allow' or 'block'. The direction must be either 'in' or 'out'. The device may specify an interface name, or 'any'. The protocol may be specified by name, or as a decimal num- ber. For TCP and UDP protocols, a port (or range, if specified with a max value) may be specified in decimal and appended to the source and/or destination address. For ICMP, a type (and optional code) may be specified in decimal. intf show Display the configuration of all network interfaces. intf get device Display the configuration for the interface specified by device. intf set device [alias host] [dst host] [inet host] [link mac] [up|down] [arp|noarp] Configure the interface specified by device. route show Display the kernel routing table. route get dst Display the route for the destination dst, specified as a hostname, IP address, or network prefix in CIDR notation. route add dst gw Add a route for the destination dst through the gateway gw. route delete dst Delete the route for the destination dst. EXAMPLES
Send a UDP datagram containing random shellcode: dnet hex "xebx1fx5ex89x76x08x31xc0x88x46x07x89" "x46x0cxb0x0bx89xf3x8dx4ex08x8dx56x0cxcdx80" "x31xdbx89xd8x40xcdx80xe8xdcxffxffxff/bin/sh" | dnet udp sport 555 dport 666 | dnet ip proto udp src 1.2.3.4 dst 5.6.7.8 | dnet send Save an ARP request in a file and send it twice: dnet arp op req sha 0:d:e:a:d:0 spa 10.0.0.3 tpa 10.0.0.4 | dnet eth type arp src 0:d:e:a:d:0 dst ff:ff:ff:ff:ff:ff > arp.pkt dnet send fxp0 < arp.pkt dnet send fxp0 < arp.pkt Send a fragmented ping packet: # Create ping packet with IP header, to set ICMP checksum echo "monkey monkey monkey monkey" | dnet icmp type 8 code 0 | dnet ip proto icmp src 1.2.3.4 dst 5.6.7.8 > ping.pkt # Chop off IP header dd if=ping.pkt of=ping.data bs=20 skip=1 # Fragment IP payload split -b 24 ping.data p. # Send fragments dnet ip id 1 off 0+ proto icmp src 1.2.3.4 dst 5.6.7.8 < p.aa | dnet send dnet ip id 1 off 24 proto icmp src 1.2.3.4 dst 5.6.7.8 < p.ab | dnet send SEE ALSO
dnet(3) AUTHORS
Dug Song <dugsong@monkey.org> BSD
October 17, 2001 BSD
All times are GMT -4. The time now is 02:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy