Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2003
    Posts
    5

    Unanswered: word deleting in a file

    dear all,
    a particular word which occures at many places in a large file is to be deleted.
    Pl help.
    TIA
    sunil

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: word deleting in a file

    cat filename | sed 's/word//g' > newfile

    Cheers

    Sathyaram

    Originally posted by sunragh
    dear all,
    a particular word which occures at many places in a large file is to be deleted.
    Pl help.
    TIA
    sunil

  3. #3
    Join Date
    Apr 2003
    Posts
    5
    Thanks a lot, it worked.

  4. #4
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: word deleting in a file

    Sorry, the script will delete all occurences of the word, even if it is a part of another word ... to delete only the word, you can do

    cat filename | sed 's/ word /g;s/ word././g'

    If you have any other format the word will occur, include them also in the above script ...

    There could be other ways also ...

    cheers

    Sathyaram

    Originally posted by sathyaram_s
    cat filename | sed 's/word//g' > newfile

    Cheers

    Sathyaram

  5. #5
    Join Date
    Apr 2003
    Posts
    5

    Re: word deleting in a file

    i have a file by name test, which contains words like raju, raju12, raju123.
    when i run this command

    # cat test |sed 's/raju/g;s/raju././g' >test1

    the output is
    sed: command garbled: s/raju/g;s/raju././g

    I am using solaris-8.





    Originally posted by sathyaram_s
    Sorry, the script will delete all occurences of the word, even if it is a part of another word ... to delete only the word, you can do

    cat filename | sed 's/ word /g;s/ word././g'

    If you have any other format the word will occur, include them also in the above script ...

    There could be other ways also ...

    cheers

    Sathyaram

  6. #6
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: word deleting in a file

    Sorry, I missed a '/' ...

    It should have been


    cat filename | sed 's/ word / /g;s/ word././g'

    In the command :

    s/word1/word2/g

    s - means search for a string
    word1 - is the search string
    word2 - is the replace with string
    g - indicates, do replacement of word1 with word2 globally

    A semi-colon( is used to a separator between two command within sed ...

    HTH

    Sathyaram


    Originally posted by sunragh
    i have a file by name test, which contains words like raju, raju12, raju123.
    when i run this command

    # cat test |sed 's/raju/g;s/raju././g' >test1

    the output is
    sed: command garbled: s/raju/g;s/raju././g

    I am using solaris-8.

  7. #7
    Join Date
    Apr 2003
    Posts
    5

    Re: word deleting in a file

    Dear sir,
    I have the following file.
    #cat file
    one farmer had
    four sons
    their names are
    raju
    raju1
    raju2
    raju3
    raju was a good boy.
    rest of raju were even good.
    #
    Now my requirement is only the word raju is tobe deleted from this file
    Pl help
    regards
    sunil

  8. #8
    Join Date
    Mar 2003
    Posts
    280
    the following remove any lines with zero or more spaces followed by raju followed by zero or more spaces

    sed -e "s/^[ ]*raju[ ]*$//g"

    if you want to get rid of the empty lines it leaves:

    sed -e "s/^[ ]*raju[ ]*$//g" -e "/^$/d"


    HTH
    /Lennart

Posting Permissions

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