For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2004 > Re: Display the line number containing a word which is consecutively duplicated,and d









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Display the line number containing a word which is consecutively duplicated,and d
Chris F.A. Johnson

2004-05-12, 7:19 pm

On 2004-05-10, Cityhunters wrote:
>
> example:
> under an input file abc:
> $cat abc
>
> if your company have the stock,than my company will have the stock too.
> so do you want to purchase the stock from us?
>
>
>
> base on above mentioned sentence.the output should be as:
>
> "Line number" "the duplicated word"
> OUTPUT
>
> 1 stock


Also:

1 company
1 have
1 the

> this is what i been trying to do so far.Can anyone help?
> thank you.^_^



awk -F ', \t' '{
n = 1
gsub(/[\.,;:]+/," ")
while ( n <= NF ) { ++w[NR," ",$n]; ++n }
}
END {
for ( word in w )
if ( w[word] > 1 ) print word
}' "$@" | sort -k1n -k2


--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com