The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to delete content in a file (delete content only) kittusri9 Shell Programming and Scripting 5 05-15-2008 02:12 PM
searching content of files in the current and sub directories tiger99 Shell Programming and Scripting 4 01-23-2008 03:11 AM
Removing lines that are (same in content) based on columns adsforall UNIX for Dummies Questions & Answers 7 11-09-2007 12:13 PM
searching for content of files Aretai UNIX for Dummies Questions & Answers 19 03-09-2007 06:44 AM
Please Help. Need Help searching for multiple stings in a file and removing them. mjs3221 UNIX for Advanced & Expert Users 2 08-19-2006 07:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-24-2005
rkumar28 rkumar28 is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 34
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.....
  #2 (permalink)  
Old 02-24-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
try
grep -v
  #3 (permalink)  
Old 02-24-2005
videsh77 videsh77 is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 144
Try

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

I hope it should work.
  #4 (permalink)  
Old 02-24-2005
rkumar28 rkumar28 is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 34
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.....
  #5 (permalink)  
Old 02-25-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Using perl....


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

Cheers
ZB
  #6 (permalink)  
Old 02-27-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
and using shell:

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

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0