LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 06-29-2007, 10:18 AM   #1
cdm33
LQ Newbie
 
Registered: Nov 2006
Posts: 6

Rep: Reputation: 0
search and replace ip address ?


Hello everyone,

Anyone know of a sed script (or any other script) which will find and replace IP addresses in a log text file ?

I've tried this but no substition takes place. I thought sed takes in regex's but this one doesn't seem to work.

sed 's/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}//g' ip_address.txt > no_ip_address.txt
 
Old 06-29-2007, 11:38 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
"s|[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} ||g" maybe?
 
Old 06-29-2007, 11:54 AM   #3
bsdunix
Senior Member
 
Registered: May 2006
Distribution: BeOS, BSD, Caldera, CTOS, Debian, LFS, Mac, Mandrake, Red Hat, Slackware, Solaris, SuSE
Posts: 1,761

Rep: Reputation: 80
I see unSpawn beat me to the punch, I did it with:
Code:
sed 's/[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}//g' ip_text.txt > no_ip_text.txt
 
Old 06-29-2007, 12:52 PM   #4
cdm33
LQ Newbie
 
Registered: Nov 2006
Posts: 6

Original Poster
Rep: Reputation: 0
great - that did it

unspawn and bsdunix - that did it. Thanks for you help. The only thing is that it also removed time stamps. I'll have to tweak it a bit.

I would have thought this would have done it also: (\d{1,3}\.){3}\d{1,3}

. . . but that didn't seem to work.
 
Old 06-29-2007, 01:13 PM   #5
cdm33
LQ Newbie
 
Registered: Nov 2006
Posts: 6

Original Poster
Rep: Reputation: 0
Actually [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} does the trick

Thanks for your help - you really helped
 
  


Reply



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
search & replace raj_sony2001 Linux - General 4 10-05-2006 02:05 PM
global search and replace? jkcunningham Linux - General 5 03-15-2006 02:43 PM
Batch search and replace devilkin Linux - Newbie 2 02-14-2005 02:39 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
Search and replace links xtrude Linux - Newbie 4 01-29-2003 11:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:12 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