![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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.. |
|
||||
|
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
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. |
|
||||
|
Hi era,
Thank you very much for your help. --Dipak |
| Sponsored Links | ||
|
|