What is the command do I need to write?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shailja
    New Member
    • Feb 2007
    • 123

    #1

    What is the command do I need to write?

    Hi

    I have one file. I want to display only duplicate records on my terminal as well as I want to remove unique lines. Which command do i need to execute to get this output?

    Kindly help me soon.

    Thanks
  • prn
    Recognized Expert Contributor
    • Apr 2007
    • 254

    #2
    OK.

    Here's a sample text file. I'll call it dup.txt:
    Code:
    The quick brown fox jumps over the lazy dog.
    The five boxing wizards jump quickly.
    Jackdaws love my big sphinx of quartz.
    Pack my box with five dozen liquor jugs.
    Quick zephyrs blow, vexing daft Jim.
    The quick brown fox jumps over the lazy dog.
    The five boxing wizards jump quickly.
    Pack my box with five dozen liquor jugs.
    I'm assuming the output you would want would be like:
    Code:
    Pack my box with five dozen liquor jugs.
    The five boxing wizards jump quickly.
    The quick brown fox jumps over the lazy dog.
    So, here is a little perl script (I'll call it dup.pl) to remove any line that is not the same as the previous line:
    [code=perl]#! /usr/bin/perl
    use strict;
    my $last = "";
    while ( <STDIN> ) {
    print if $_ eq $last;
    $last = $_;
    }[/code]
    Now you can use it like this:
    Code:
    sort dup.txt | dup.pl
    HTH,
    Paul

    Comment

    Working...