Searching and Removing File Content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching and Removing File Content
# 1  
Old 02-24-2005
Searching and Removing File Content

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. 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....


Any help will be appreciated.....
rkumar28
# 2  
Old 02-24-2005
try
grep -v
# 3  
Old 02-24-2005
Try

awk '$0!~/c00200_00_000/' test1.txt > test2.txt

I hope it should work.
# 4  
Old 02-24-2005
Hitting another issue....

Thanks for the quick reply......I tried
grep - v and it worked....

I am hitting another problem using this......If I create another file(s)..I get into space issue.....Is there a way to remove the c00200_00_000 ....from the original file without creating a copy of it...

I tried something like this:
grep -v c00200_00_000 test1.txt >test2.txt ...> I am copying the filtered data into another file test2.....
Is there a way I can remove it from test1.txt without creating a copy test2.txt....

Thanks again for your time and reply.....
rkumar28
# 5  
Old 02-25-2005
Using perl....

Code:
perl -pi~ -e "s/^c00200_00_000.*\n//" my_file

Cheers
ZB
# 6  
Old 02-27-2005
and using shell:
Code:
/bin/echo '/c00200_00_000/d\nwq!' | ex - test1.txt

# 7  
Old 02-27-2005
In order to perform a global delete, you will need to modify vgersh99's code slightly by specifying a global modifier....

Code:
/bin/echo 'g/c00200_00_000/d\nwq!' | ex - test1.txt

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching content of a variable using awk

so i'm running a variation of the following command a few times in my script: echo "${TOTALRunning}" | awk -F"" '/'"${PROCSEARCH}"'/ {print $2}' | tr '\n' '|' unfortunately i cant paste the content of the variable TOTALRunning into this thread for security reasons. what i want to do is... (9 Replies)
Discussion started by: SkySmart
9 Replies

2. Shell Programming and Scripting

Searching the content of one file using the search key of another file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search key is... (3 Replies)
Discussion started by: csim_mohan
3 Replies

3. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

4. UNIX for Advanced & Expert Users

Removing files based on name and content

Consider i have 2 directories a1 and a2. under a1, i have below files test1 test2 test3. Under a2,i have below files. test1 test2 test3 test4 test5My requirement is i will pass the directory names(2 parameters) and directory in which files needs to be removed.(3rd parameter) a)first... (11 Replies)
Discussion started by: pandeesh
11 Replies

5. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

6. Shell Programming and Scripting

searching & replacing/removing only certain HTML tags

I generally save a lot of web pages for reading offline which works out great for school. Now I have to spend a lot of time on the bus and I am looking for the best way to read some of these webpages using my Nokia 7610. I have uploaded the files to my phone, but they are deadly deadly slow to... (2 Replies)
Discussion started by: naphelge
2 Replies

7. Shell Programming and Scripting

searching content of files in the current and sub directories

Hi I was wondering why command 2 doesn't work like command 1 below. 1. find . -exec grep "test" '{}' \; -print 2. ls -R | grep "test" I am trying to search "test" from all the files in the current and sub directories. What's wrong with my command 2? Thanks in advance for your help (4 Replies)
Discussion started by: tiger99
4 Replies

8. UNIX for Dummies Questions & Answers

Removing lines that are (same in content) based on columns

I have a file which looks like AA BB CC DD EE FF GG HH KK AA BB GG HH KK FF CC DD EE AA BB CC DD EE UU VV XX ZZ AA BB VV XX ZZ UU CC DD EE .... I want the script to give me only one line based on duplicate contents: AA BB CC DD EE FF GG HH KK AA BB CC DD EE UU VV XX ZZ (7 Replies)
Discussion started by: adsforall
7 Replies

9. UNIX for Dummies Questions & Answers

searching for content of files

Hi, This question may be quite newbish. I've stored a few files on my Unix system and am wondering how to search for their contents (i.e. I input the keyword and get a list of files with this keyword) I'd then like to put it on my website (php). I thought of find and grep, but am not... (19 Replies)
Discussion started by: Aretai
19 Replies

10. UNIX for Advanced & Expert Users

Please Help. Need Help searching for multiple stings in a file and removing them.

Please help. Here is my problem. I have 9000 lines in file a and 500,000 lines in file b. For each line in file a I need to search file b and remove that line. I am currently using the grep -v command and loading the output into a new file. However, because of the size of file b this takes an... (2 Replies)
Discussion started by: mjs3221
2 Replies
Login or Register to Ask a Question