View Single Post

  #2 (permalink)  
Old 04-07-2008
Chris F.A. Johnson
 
Posts: n/a
Default Re: reverse effect of uniq -c

On 2008-04-07, A wrote:
> Hi,
>
> I am wondering if there is a simple shell manipulation that can
> produce the reverse effect of using uniq -c. In other words, how can I
> create a file x.txt so that when I type 'uniq -c x.txt' on the shell,
> I get the following output?


Feed the output of uniq-c to:

awk '{ n = $1; sub( ".*" $1 " " ,"") ; while ( n-- ) print }'

> 4 "0" "1" "1" "1" "1"
> 31 "0" "2" "0" "0" "0"
> 142 "0" "2" "0" "0" "1"

....
> 1 "2" "2" "0" "0" "NA"
> 6 "2" "NA" "1" "1" "0"
> 1 "2" "NA" "1" "NA" "0"
> 1 "NA" "2" "0" "0" "1"



--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Reply With Quote