Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2005
    Posts
    17

    Unanswered: Deleting lines from a file

    sed '/^[HS]/ d' command will delete all the lines from a file which starts with 'H' or 'S'. But I want to delete all the lines that start with 'H' or 'SLSC' . Can anyone please let me know how to do it?

    Thanks.

  2. #2
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Code:
    sed '/^H/d' '/^SLSC/d' file
    You can combine different expressions in one sed command. Check your man pages for the exact syntax. In Linux e.g. for a command with several expressions every expression has to be preceded by the -e flag.

    Regards

  3. #3
    Join Date
    Jun 2005
    Posts
    17
    Thanks.
    I cant get it to work. My actual purpose is different. I want to copy all the lines starting with 'H' or 'SLSC' to a new file.

    if it is 'H' or 'S', sed '/^[HS]/ !d' file1 > file2 will do.
    but i dont know how to do 'H' and 'SLSC' together. I dont want 'S' alone .
    I want to copy all the lines starting with 'H' or 'SLSC' to the second file.
    Last edited by bufsn; 05-17-07 at 16:11.

  4. #4
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    In that case forget my previous example and try:
    Code:
    sed -ne '/^H/p' -e '/^SLSC/p' file1 > file2
    This works in Linux and AIX and probably in all the other flavours...

    Regards

  5. #5
    Join Date
    Jun 2005
    Posts
    17
    Thanks. It works.

  6. #6
    Join Date
    Sep 2007
    Posts
    11
    Hi .. just to add on this ..

    i need to find a word example:coys111 once this string is found .. need to delete the lines which are 5 lines above and 4 lines which are below !!!

    Can anyone help me on this >>>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •