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

    Unanswered: Searching and Removing String in a file

    Hi,

    I am trying to search a character in a file and remove it from that file....

    My file looks something like this:
    test1.txt
    ckj12300_00|123|var1|10.2
    ckj00200_12|444|var2|11.2
    ckj00200_14|4556|var3|33.5
    c00200_00_000|4558|var4|33.5
    ckj00200_14|4553|var5|33.5
    c00200_00_000|453|var7|33.5
    ckj00200_14|454|var8|33.5
    c00200_00_000|4567|var50|40.2

    and so on....

    I have to find rows that has c00200_00_000 and remove it from file(s). The files are about 33 MB and there are quite a few rows with c00200_00_000.

    I tried grep -v c00200_00_000 test1.txt >test2.txt .....>This worked perfectly well but I am hit a space issue as I am copying the filtered data into another file test2.....
    Is there a way I can remove it from test1.txt(original file) without creating a copy test2.txt....


    Any help will be appreciated.....

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    pls don't cross post to multiple forums and use FAQ's and Google to find relative topics.
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Hi rkumar28,
    try this :

    I test it with a file greater then yours, and it works.

    # load file into memory
    i=`cat test1.txt`
    # remove old file
    rm test1.txt
    create new file without existing string "c00200_00_000"
    for a in `echo $i`
    do
    echo $a | grep -v "c00200_00_000" >> test1.txt
    done

    # I hope it works in your environment
    Greetings from germany
    Peter F.

Posting Permissions

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