Results 1 to 6 of 6

Thread: Deleting line with sed command in unix/linux

  1. #1
    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 ?

  2. #2
    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.

  3. #3
    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

  4. #4
    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.

  5. #5
    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.

  6. #6
    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.

Similar Threads

  1. Command Line in Linux to clear the /tmp folder
    By BBC123 in forum Operating Systems
    Replies: 4
    Last Post: 26-02-2012, 02:41 PM
  2. How to perform Cut and paste from command line in Linux
    By Malik B in forum Operating Systems
    Replies: 4
    Last Post: 11-11-2010, 04:12 PM
  3. Linux and UNIX shutdown command help
    By Morea in forum Operating Systems
    Replies: 4
    Last Post: 27-03-2010, 09:32 PM
  4. Inroduction of Linux command line
    By Ceesar in forum Operating Systems
    Replies: 5
    Last Post: 31-12-2009, 02:20 AM
  5. Download files from Linux command line
    By chaosblade in forum Operating Systems
    Replies: 3
    Last Post: 28-08-2009, 03:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,616,933.60150 seconds with 17 queries