Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Deleting line with sed command in unix/linux

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 12-03-2010
Member
 
Join Date: Nov 2008
Posts: 240
Deleting line with sed command in unix/linux
  

Hello guys,
I studied about this command but didn't tried and it is a screen shot to show you,how a sed command deletes the line from file.

sed "/$textsearch/d" My_list

will delete any line in the file My_list that matches $textsearch.I want to know how exactly i use this command to delete the line from the file so that it doesn't appear next time I open the file ?

Reply With Quote
  #2  
Old 12-03-2010
Member
 
Join Date: May 2008
Posts: 2,297
Deleting line with sed command in unix/linux

This is one of the procedure through which you can delete particular line from the file.There are some options are being added with the command.The options are used to count and detect the number of lines.

Code:
(echo "g/${textsearch}/d"; echo 'wq') | ex -s My_list
"g/${textsearch}/d" this line performs the 'delete' operation and 'wq' Writes the file to disk and 'Quits' after updating the file.
Reply With Quote
  #3  
Old 12-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,393
Deleting line with sed command in unix/linux

I faced this situations,when I tried to execute the above written command and searched a lot of description but not getting success to execute without any help.

On the other section of the search means beside of this code,I got a command which is able to delete the same and matching with the first posted thread but you have to do some little bit changes to before executing this command.

sed "/$textsearch/d" My_list >tmp
mv tmp My_list
Reply With Quote
  #4  
Old 12-03-2010
Member
 
Join Date: May 2008
Posts: 2,389
Deleting extraneous characters with sed command

You can delete the extraneous characters like <,*,#,@,etc.The file are full of these type of text and you want remove those extraneous characters from the file and when we open the file,the file should be looks like without any extraneous characters :

You have to do some small changes in the code :

Code:
sed -n -e "s/^[^<]*<\([^>]*\)>.*/\1/p"
The code will delete all the specified characters from the file,this command would be executed with the help of echo command.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 12-03-2010
Member
 
Join Date: Feb 2008
Posts: 1,852
Deleting line with sed command in unix/linux

Hi,

This is one more example which can do this same means the deletion of extraneous characters on the command prompt.The command is combination of cut command.

It would look same as the above suggested command by the expert members.

$echo "Good Text<extraneous characters" | cut -d "<" -f1

Just specify the characters in the double court associated with cut command.
Reply With Quote
  #6  
Old 20-03-2010
Member
 
Join Date: Feb 2010
Posts: 1
Re: Deleting line with sed command in unix/linux

Hi Fragman,

use this command:
sed -e "s/$textsearch//g" My_list > New_My_list

where New_My_list will be ur new file name which contains all the content of the file My_list except those lines.

Try this.

Quote:
Originally Posted by Fragman View Post
Hello guys,
I studied about this command but didn't tried and it is a screen shot to show you,how a sed command deletes the line from file.

sed "/$textsearch/d" My_list

will delete any line in the file My_list that matches $textsearch.I want to know how exactly i use this command to delete the line from the file so that it doesn't appear next time I open the file ?

Last edited by nil_nilava : 20-03-2010 at 09:50 PM.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Deleting line with sed command in unix/linux"
Thread Thread Starter Forum Replies Last Post
Command Line in Linux to clear the /tmp folder BBC123 Operating Systems 4 26-02-2012 02:41 PM
How to perform Cut and paste from command line in Linux Malik B Operating Systems 4 11-11-2010 04:12 PM
Linux and UNIX shutdown command help Morea Operating Systems 4 27-03-2010 09:32 PM
Inroduction of Linux command line Ceesar Operating Systems 5 31-12-2009 02:20 AM
Download files from Linux command line chaosblade Operating Systems 3 28-08-2009 03:18 PM


All times are GMT +5.5. The time now is 12:09 PM.