LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-17-2010, 10:26 PM   #1
ejinh
LQ Newbie
 
Registered: Aug 2010
Posts: 8

Rep: Reputation: 0
awk: how to exclude last several characters


Guys, Good Day.

any tips from you guys on how to filter my awk output?
I want to exclude last 5 characters using awk in my tcpdump result.

ex.
192.168.34.12.443:

I don't want to include ".443:" in my tcpdump using awk.

Thanks a ton.
 
Old 08-18-2010, 01:13 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Must this be done with awk?

A sed solution:

echo "192.168.34.12.443:" | sed 's/\.443://'

or, if the last characters can be any other port:

echo "192.168.34.12.10245:" | sed 's/\.[1-9][0-9]*://'

Hope this helps.
 
Old 08-18-2010, 01:23 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
his tcpdump output is more than that. This is the other thread
 
Old 08-18-2010, 01:35 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

@ghostdog74: Too little information by the OP _and_ cross-posting. Don't you just love it when people waste our time
 
Old 08-18-2010, 02:54 AM   #5
ejinh
LQ Newbie
 
Registered: Aug 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Hi guys, thanks for the response. Sorry for asking and giving you a little info.

What I want is I have this PF running under OpenBSD for the reason to block "UltraSurf", "Your-Freedom", "FreeGate" etc. I was able to block those proxies running under port 443 and I'm using this TCPDUMP to capture if what are those IP's he's digging. My aim here is to capture those IP addresses and automatically will be added to my blacklist.

To capture those IP addresses, I'm using this command "tcpdump -n -q -t -i pflog0 port 443" and it will give me this results:

192.168.77.201.4103 > 61.227.121.97.443: tcp 0 (DF)
192.168.77.201.4104 > 61.227.121.97.443: tcp 0 (DF)
192.168.77.201.4106 > 218.171.71.96.443: tcp 0 (DF)
192.168.77.201.4107 > 114.40.18.243.443: tcp 0 (DF)
192.168.77.201.4108 > 114.40.18.243.443: tcp 0 (DF)
192.168.77.201.4109 > 220.129.163.81.443: tcp 0 (DF)
192.168.77.201.4113 > 118.160.37.170.443: tcp 0 (DF)
192.168.77.201.4116 > 219.85.97.70.443: tcp 0 (DF)
192.168.77.201.4117 > 114.27.242.77.443: tcp 0 (DF)
192.168.77.201.4118 > 114.27.242.77.443: tcp 0 (DF)


With that result I just want only to get those IP address and put it inside my "blacklistip" file automatically.

Hope this helps.

Thanks a lot guys.

Last edited by ejinh; 08-18-2010 at 02:57 AM.
 
Old 08-18-2010, 03:10 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

I do believe this was already answered by ghostdog74 in your other thread (post #10).
 
Old 08-18-2010, 03:19 AM   #7
ejinh
LQ Newbie
 
Registered: Aug 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Hello Guys. Good Day.

Thanks a lot for helping me with this. And thanks as well for giving me some info on how to use SED.
 
  


Reply

Tags
awk, filtering, output, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How do I exclude multiple directories in awk with find? Damarr Linux - Newbie 11 05-24-2010 02:52 PM
Scramble characters in AWK MTK358 Programming 21 05-13-2010 04:05 PM
[SOLVED] Problems to exclude lines and bad filter within AWK script cgcamal Programming 7 04-30-2010 12:38 AM
How exclude | from txt.file using awk or sed? sarajevo Programming 2 08-21-2006 07:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration