Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-29-2003, 10:10 PM   #1
LQ Newbie
Registered: Oct 2003
Posts: 8

Rep: Reputation: 0
Bash Scripting Question

I'm trying to organize IP Addresses in a log by class... I currently have uniquely parsed out the IP Addresses from the log so I have a list of IPs. My problem here lies that I would like to take all IPs starting with 1-128 and store then into a seperate file. I have tried egrep (must be doing something wrong here). Any ideas?

egrep -o `[[1-128]]\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}` IPTEMP | sort -r >> CLASSA

If Awk would be better let me know... but I'm a little new with AWK too.

Thanks in advance,
Old 10-30-2003, 10:00 AM   #2
LQ Newbie
Registered: Oct 2003
Posts: 5

Rep: Reputation: 0
Using awk it's simple

awk -F. '{if ($1<=128) print $0}' IPTEMP | sort -r >> CLASSA

-F set field separator to '.'
$1 is the first field
$0 is the whole line (ip nr)

Good luck
Old 10-30-2003, 10:16 AM   #3
LQ Newbie
Registered: Oct 2003
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks a ton. I knew there had to be an easier way.


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting question ajaye1971 Linux - Newbie 1 11-16-2005 07:29 PM
Bash scripting question. pete1234 Programming 23 09-22-2005 06:52 PM
bash scripting question mehesque Programming 2 03-07-2004 01:37 PM
Bash scripting question. welby Linux - Software 1 01-14-2004 10:05 AM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 09:06 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:01 PM.

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