The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 remove the lines from file using perl dipakg Shell Programming and Scripting 5 06-03-2008 07:49 AM
Remove duplicates from File from specific location gopikgunda Shell Programming and Scripting 1 04-09-2008 02:16 AM
remove specific lines from flat file using perl meghana Shell Programming and Scripting 12 02-12-2008 09:50 PM
how to remove specific lines from a file bluemoon1 Shell Programming and Scripting 17 10-07-2007 10:40 PM
remove specific lines from a file hcclnoodles Shell Programming and Scripting 14 09-07-2006 12:31 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-04-2008
dipakg dipakg is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
How to remove the specific lines from file using perl

Can anyone tell me what could be the solution to following :

I have one .txt file which contains some "seed" information. This seed may appear multiple time in the file so what I want do is if this seed appears again in the file then that line should be removed.

Please provide the script code also:

Here in I am attaching the text file.
Thanks in advance..
Attached Files
File Type: txt my_log.txt (187.1 KB, 77 views)
  #2 (permalink)  
Old 06-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
So if the tenth field is identical to one we have seen before, remove the whole line?

Code:
perl -ane 'print unless $seen{$F[9]}++' my_log.txt
(Perl arrays are numbered from zero, so $F[9] is the tenth field. The -a option causes Perl to split the input line into the array @F, somewhat similarly to how awk works.)

The input line is printed unless the hash %seen already has an entry for the tenth field. We also add one to its value, which causes it to be set (to one) if it didn't exist before. Thus, the %seen value for the current seed will be set the next time it is encountered.

For the sample file you posted, this reduces 1,274 lines to just 72 lines.
  #3 (permalink)  
Old 06-05-2008
ThobiasVakayil ThobiasVakayil is offline
Registered User
  
 

Join Date: May 2006
Posts: 63
if you want to remove the lines which is having the word seed, execute the following command :

grep -v "seed" my_file.txt
  #4 (permalink)  
Old 06-05-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
this is the same question posted here
  #5 (permalink)  
Old 06-11-2008
dipakg dipakg is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
Hi era,

Thank you very much for your help.

--Dipak
Sponsored Links
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:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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