Find the answer to your Linux question:
Results 1 to 6 of 6
hi all how to remove the line first we have to search the line if the line exist remove the line else dont do anything. for example "disable_from_plugins" , this ...
  1. #1
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247

    remove the line

    hi all
    how to remove the line
    first we have to search the line
    if the line exist remove the line
    else
    dont do anything.

    for example "disable_from_plugins" , this is the word containing the line
    search the line and delete.. programatically

    can you please help me

    thank you in advance
    "Relationships are built on trust and communication"

  2. #2
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247
    hi i tried up to this
    Code:
    cat munna.c | grep disable_from_plugins
    the output is
    g_ref(disable_from_plugins);
    then hoe to remove the line that containing "disable_from_plugins".
    and save the file..

    and
    if the word not find....
    dont do any thing..

    i prefer c or script.

    please help me

    thank you in advance
    "Relationships are built on trust and communication"

  3. #3
    Just Joined!
    Join Date
    Feb 2006
    Posts
    6
    I would try
    Code:
    cat munna.c | grep -v disable_from_plugins > outputfile
    This will output all lines except those matching the pattern disable_from_plugins, and direct it into outputfile.

  4. #4
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    You don't need the cat - give grep the filename, or redirect the file. These are pretty much equivalent:
    Code:
    grep -v disable_from_plugins munna.c >outfile
    grep -v disable_from_plugins <munna.c >outfile
    Or you could use sed and modify the source file directly:
    Code:
    sed -i /disable_from_plugins/d munna.c

  5. #5
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247
    Quote Originally Posted by scm View Post
    You don't need the cat - give grep the filename, or redirect the file. These are pretty much equivalent:
    Code:
    grep -v disable_from_plugins munna.c >outfile
    grep -v disable_from_plugins <munna.c >outfile
    Or you could use sed and modify the source file directly:
    Code:
    sed -i /disable_from_plugins/d munna.c
    hi
    i have another problem with this
    i would not like to remove the line.
    just wanna do some changes in the line..


    for example "disable_from_plugins" , this is the word containing the line
    search the line and change the line i.e
    rame("rr.disable_from_plugins", 2);
    to
    "rame("rr.disable_from_plugins", 1);"
    and save by programatically

    can you please help me

    thank you in advance
    "Relationships are built on trust and communication"

  6. #6
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    If this is stuff you're going to be doing regularly, and the solution fits, you might want to use the c pre processor for 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
  •  
...