Register
It is currently Tue Oct 21, 2014 12:24 pm

just asking about remove script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Tue Dec 11, 2007 10:24 pm   

Joined: Tue Dec 11, 2007 10:21 pm
Posts: 20
Hello is posible to make a bash script to remove line from onther file?
for example i have file:

/bin/example
example with lines
go to one
go to two
go to threee

how can i build a script to search in /bin/example and remove line two or three?

thank you!


Top
 Profile  
 PostPosted: Wed Dec 12, 2007 11:29 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
The 'sed' command may be a good place to start. There are lots of options for search/replace and removing text selectively. Here's an example:

Code:
wendtj@HOUWENDTJ03>$ cat /tmp/example
this is line one
this is line two
this is line three
this is line four
this is line five
this is line six

wendtj@HOUWENDTJ03>$ sed '/this.is.line.four/d' /tmp/example
this is line one
this is line two
this is line three
this is line five
this is line six


Here's a great page with some sed one-liners and what they do:

http://sed.sourceforge.net/sed1line.txt

There's also a flag to edit the file in-place instead of just printing the output to the console. The man page, combined with that page linked above, should help you out a lot!

Hope this helps!
-Jeo


Top
 Profile YIM  
 PostPosted: Wed Dec 12, 2007 11:32 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
If you wanted to go by line numbers, rather than text matching, you can do that with sed as well. I think you can also use awk for that.


Top
 Profile YIM  
 PostPosted: Wed Dec 12, 2007 11:39 am   

Joined: Tue Dec 11, 2007 10:21 pm
Posts: 20
[quote="jeo"]The 'sed' command may be a good place to start. There are lots of options for search/replace and removing text selectively. Here's an example:

Code:
wendtj@HOUWENDTJ03>$ cat /tmp/example
this is line one
this is line two
this is line three
this is line four
this is line five
this is line six

wendtj@HOUWENDTJ03>$ sed '/this.is.line.four/d' /tmp/example
this is line one
this is line two
this is line three
this is line five
this is line six


that is a good ideea but , he is not removing the line two , if i look into example line is still there, i need it to be remove from file .i made a script to block a ip into firewall rules , and i whant to make one to be removed also but how to remove a line from a file? this is my problem.


Top
 Profile  
 PostPosted: Wed Dec 12, 2007 12:23 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Hi redrack!

To remove it from the file, you'll need to use the -i flag ( "i" is for "in-place" )

# sed -i '/this.is.line.four/d' /tmp/example

Hope that helps!
-Jeo


Top
 Profile YIM  
 PostPosted: Wed Dec 12, 2007 12:54 pm   

Joined: Tue Dec 11, 2007 10:21 pm
Posts: 20
jeo wrote:
Hi redrack!

To remove it from the file, you'll need to use the -i flag ( "i" is for "in-place" )

# sed -i '/this.is.line.four/d' /tmp/example

Hope that helps!
-Jeo


yeah now works thanks a lot :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 34 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP