Searching and Removing data from file

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
rkumar28
Participant
Posts: 43
Joined: Tue Mar 30, 2004 9:39 am

Searching and Removing data from file

Post by rkumar28 »

Hi,

Before loading data form flat file......I am trying to search a character in a file and remove it from that file using unix command....

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 . The file is about 33 MB and there are quite a few rows with c00200_00_000.

I tried grep c00200_00_000 test1.txt >test2.txt .....>This command only finds the c00200_00_000 and puts it in test2.txt but does not remove it from file....

Is there a way to remove these rows from the file using unix command....


Any help will be appreciated.....

Thanks
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Try "man grep" on your version of Unix. The "-v" option should be available for returning non-matching rows.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The grep command has a -v option to perform a reverse search. This should achieve what you need.

Code: Select all

grep -v c00200_00_000 test1.txt >test2.txt 
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

If you are processing the data in DataStage and sending it through a transformer you will find it faster to remove the string in the transformer rather then a Unix command.
Post Reply