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
Cityhunters

2004-05-12, 7:19 pm

Ed Morton <morton@lsupcaemnt.com> wrote in message news:<RrudnYWEx6AV7gPdRVn-vA@comcast.com>...
> Cityhunters wrote:
>
> That's a very different requirement from your earlier post, so the
> solutions that were posted before don't apply to this problem. I'm not
> really sure what you're asking though: do you want to find lines that
> have the same word repeated on that line, or lines that contain the same
> word as the preceeding line, or is each word on it's own line? Do you
> want every line number for those lines that have consecutive words, or
> every line but the first, or only the first, or only the last? A sample
> input file and desired output would be a big help. To illustrate one
> possibility, if your input file contains:
>
> bob
> bill
> bill
> bill
> joe
> bill
> sue
>
> and you want the output to be:
>
> 3,bill
> 4,bill
>
> then this will do it:
>
> awk '$1 == prev{print NR, prev}{prev = $1 }'
>
> Regards,
>
> Ed.








thanks for all the help.


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


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







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

Copyright 2008 codecomments.com