Sponsored Content
Top Forums Shell Programming and Scripting Sed to delete exactly match pattern and print them in other file Post 302212022 by new_buddy on Saturday 5th of July 2008 09:12:26 PM
Old 07-05-2008
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 the printed lines. I found that sed print lines that match port 4513 although I just want exactly the 4513.
Here is my code
Code:
sed -n -f print.sed tcpfile >> tcpfile.out
sed -f delete.sed tcpfile >>tcpfile.delete

Example of the print.sed
Code:
/451/p
/46[6-7][1-4]/p
...

Example lines in tcpfile
Code:
src=78.136.25.50 dst=192.168.133.202 bytes=610 proto=6 sport=80 dport=3159
src=89.1.65.142 dst=192.168.133.202 bytes=184 proto=6 sport=43954 dport=1153
src=72.14.217.189 dst=192.168.133.202 bytes=270 proto=6 sport=80 dport=3145
src=78.136.25.50 dst=192.168.133.202 bytes=610 proto=6 sport=80 dport=3158
src=208.70.8.23 dst=192.168.133.202 bytes=2472 proto=6 sport=80 dport=1447
src=208.70.8.23 dst=192.168.133.202 bytes=2526 proto=6 sport=80 dport=1811

Really need help. 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: 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 time=1209515280-1209515340 dst=192.168.133.202 src=208.70.8.23 bytes=2472 proto=6 sport=80 dport=1447... (6 Replies)
Discussion started by: new_buddy
6 Replies

3. Shell Programming and Scripting

sed print all lines after pattern match

HiCan someone show me how to print all lines from a file after a line matching a pattern using sed?Thanks (13 Replies)
Discussion started by: steadyonabix
13 Replies

4. Shell Programming and Scripting

Sed delete blank lines upto first pattern match

Hi Im trying to do the following in sed. I want to delete any blank line at the start of a file until it matches a pattern and then stops. for example: Input output: I have got it to work within a range of two patterns with the following: sed '/1/,/pattern/{/^]*$/d}' The... (2 Replies)
Discussion started by: duonut
2 Replies

5. Shell Programming and Scripting

sed print from last occurrence match until the end of file

Hi, i have file f1.txt with data like: CHECK a b CHECK c d CHECK e f JOB_START .... I want to match the last occurrence of 'CHECK' until the end of the file. I can use awk: awk '/^CHECK/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' f1.txt | tail +2Is there a cleaner way of... (2 Replies)
Discussion started by: ysrini
2 Replies

6. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

7. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

8. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

9. Shell Programming and Scripting

Egrep patterns in a file and limit number of matches to print for each pattern match

Hi I need to egrep patterns in a file and limit number of matches to print for each matched pattern. -m10 option is not working out in my sun solaris 5.10 Please guide me the options to achieve. if i do head -10 , i wont be getting all pattern match results as output since for a... (10 Replies)
Discussion started by: ananan
10 Replies

10. UNIX for Beginners Questions & Answers

sed script to delete the last word after a last pattern match

Hi Guys , I am having a file as stated below File 1 sa0 -- i_core/i_core_apb/i_afe0_controller/U261/A sa0 -- i_core/i_core_apb/i_afe0_controller/U265/Z sa1 -- i_core/i_core_apb/i_afe0_controller/U265/A sa1 -- i_core/i_core_apb/i_afe0_controller/U268/Z sa1 -- ... (7 Replies)
Discussion started by: kshitij
7 Replies
RASORT(1)						      General Commands Manual							 RASORT(1)

NAME
rasort - sort argus(8) data file. COPYRIGHT
Copyright (c) 2000-2003 QoSient. All rights reserved. SYNOPSIS
rasort [[-M sortmode] [sortmode] ...] [raoptions] DESCRIPTION
Rasort reads argus data from an argus-data source, sorts the records based on the criteria specified on the command line, and outputs a valid argus-stream. OPTIONS
Rasort, like all ra based clients, supports a number of ra options including filtering of input argus records through a terminating filter expression. See ra(1) for a complete description of ra options. rasort(1) specific options are: -M sortmode Supported sortmodes are: time record start time <default> startime record start time <default> lasttime record last time. trans aggregation record count. dur record total duration. avgdur record average duration. saddr source IP addr. daddr destination IP addr. proto transaction protocol. sport source port number. dport destination port number. stos source TOS byte value. dtos destination TOS byte value. sttl src -> dst TTL value. dttl dst -> src TTL value. bytes total transaction bytes. sbytes src -> dst transaction bytes. dbytes dst -> src transaction bytes. pkts total transaction packet count. spkts src -> dst packet count. dpkts dst -> src packet count. load bits per second. loss pkts retransmitted or dropped. rate pkts per second. tranref argus transaction reference number. seq argus sequence number. srcid argus source identifier. INVOCATION
A sample invocation of rasort(1). This call reads argus(8) data from inputfile and sorts the IP protocol based argus(8) data, first by the destination IP address, then by the service (destination) port number and then by the source IP address, and writes the results to stdout. For most services, this arranges argus(8) formatted data by server, service, and then by client. rasort -r inputfile -M daddr dport saddr - ip SEE ALSO
ra(1), rarc(5), argus(8), tcpdump(1) FILES
AUTHORS
Carter Bullard (carter@qosient.com). BUGS
07 November 2000 RASORT(1)
All times are GMT -4. The time now is 02:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy