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
Searching and Removing data from file
Moderators: chulett, rschirm, roy
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 3593
- Joined: Thu Jan 23, 2003 5:25 pm
- Location: Australia, Melbourne
- Contact:
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.
Certus Solutions
Blog: Tooling Around in the InfoSphere
Twitter: @vmcburney
LinkedIn:Vincent McBurney LinkedIn
Blog: Tooling Around in the InfoSphere
Twitter: @vmcburney
LinkedIn:Vincent McBurney LinkedIn