If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Searching and Removing String in a file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-05, 22:05
rkumar28 rkumar28 is offline
Registered User
 
Join Date: Apr 2003
Posts: 5
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.....
Reply With Quote
  #2 (permalink)  
Old 02-24-05, 22:58
vgersh99 vgersh99 is offline
Registered User
 
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> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 02-27-05, 14:46
fla5do fla5do is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On