how to print duplicate words in said text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Harikumar143
    New Member
    • Dec 2013
    • 2

    how to print duplicate words in said text file

    i gave input file and output file.can u tell me script.
    Attached Files
  • dianagaby2002
    New Member
    • Jul 2012
    • 9

    #2
    In which programming language?

    Comment

    • Harikumar143
      New Member
      • Dec 2013
      • 2

      #3
      perl programing language

      Comment

      • Raj4perl
        New Member
        • Aug 2014
        • 12

        #4
        Hi Hari,

        here's the script for following output. There is a small error in the output.. couldn't fix it... :(

        it could be great if you can explain the logic behind the generation of output.!!

        Code:
        use warnings;
        @values = 0;
        $file = "input.txt";
        open HNDL, "$file" or die "Unable to open the text file";
        
        unlink "output_f.txt";
        $out_file = "output_f.txt";
        open HNDLR, "+>>$out_file" or die "Unable to generate output file";
        while(<HNDL>)
        	{
        	$line = <HNDL>;
        	@values = split(' ', $line);
        		if($values = !/support/ || !/name/)
        			{
        				print HNDLR " ",$values[1]," ","==>"," ";
        			}
        			print HNDLR $values[1]," ";
        			print HNDLR $values[0],"\n";
        			print HNDLR "          ",$line;			
        	}
        	
        
        -------------------output-----
        
         abcd ==> abcd support
                  support abcd                                           
        [B] support ==> support wqxz (error)
                  wqxz support
        [/B] asdf ==> asdf name
                  name asdf
         jklm ==> jklm support
                  support jklm
         srkl ==> srkl support
                  support srkl
         cvbn ==> cvbn name
                  name cvbn
         mnopq ==> mnopq name
                  name mnopq
         uyti ==> uyti support
                  support uyti
         ghjf ==> ghjf support
                  support ghjf
         awsz ==> awsz name
                  name awsz


        -Raj
        Last edited by Rabbit; Aug 15 '14, 10:39 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

        Comment

        Working...