LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-28-2005, 02:04 PM   #1
spiffytech
Member
 
Registered: Dec 2005
Location: NC, USA
Distribution: (K)ubuntu
Posts: 139

Rep: Reputation: 15
Make a script remove lines from a file?


I need to make my script remove lines from a file containing certain IPs. The only way I can think of to do this is to get grep to echo back the line numbers that have that IP and have sed remove those lines. How would I get each of those parts to work? Is there a better way to do it?
 
Old 12-28-2005, 02:46 PM   #2
tkrin
Member
 
Registered: Nov 2003
Distribution: Slackware / CentOS / Mint / Ubuntu
Posts: 42

Rep: Reputation: 15
How about a perl one liner:

perl -pi -e 's/^.*111.222.333.444.*\n$//g' FILENAME
 
Old 12-28-2005, 02:55 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
I'm assuming that your data file is called logdata, that you have a list of IP addresses to filter in a file called filters (stored one IP address per line) and that your filtered data will go in filtered-data. Use something like:

Code:
grep -v -f filters logdata > filtered-data
I'm also hoping that I've correctly understood what you were asking for
 
Old 12-28-2005, 02:57 PM   #4
Oxagast
Member
 
Registered: Aug 2003
Location: Mocksville, NC, USA
Distribution: Gentoo, Slackware.
Posts: 410

Rep: Reputation: 30
Try:

cat FILENAME | grep -v 111.222.333.444 > FILENAME
 
Old 12-28-2005, 02:59 PM   #5
spiffytech
Member
 
Registered: Dec 2005
Location: NC, USA
Distribution: (K)ubuntu
Posts: 139

Original Poster
Rep: Reputation: 15
How can I insert a variable into that perl line? The script compares IPs with a list of IPs, and returns the approved IPs into a variable. How do I insert the IPs in that variable into the perl line automatically?
 
Old 12-29-2005, 11:50 AM   #6
spiffytech
Member
 
Registered: Dec 2005
Location: NC, USA
Distribution: (K)ubuntu
Posts: 139

Original Poster
Rep: Reputation: 15
I got it working, thanks!
 
  


Reply


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
Remove odd lines from a text file Mr. Gone Programming 2 09-19-2005 11:16 AM
How to remove lines from a file doza Linux - General 2 04-27-2005 11:59 AM
remove identical lines in a file benjithegreat98 Linux - General 4 04-24-2004 06:12 AM
How do i remove blank lines from a file? kakho Programming 1 04-15-2004 03:57 AM
[bash] remove lines from a file Drimo Programming 3 03-20-2004 11:16 AM


All times are GMT -5. The time now is 04:34 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration