How to list all the prime factor?

November 2nd, 2006 mysurface Posted in Calculation, cut, factor | Hits: 61509 | 1 Comment »

Are you thinking of using c/c++ or bash script to do that? Don’t do that, linux have ready made command. Its call factor.

Let say I want to list the prime factor for 232.

factor 232

The result will be

232: 2 2 2 29

What if I want only the factor with the “232:” ? We can use cut with -complement.

factor 232 | cut -f1 -d" " --complement

By specifying -f1 -d” “, it suppose to extract column 1, but because I ask it for complement, I get this:

2 2 2 29

One Response to “How to list all the prime factor?”

  1. Check bellow link for finding prime factors of a given number bash script
    http://bashscript.blogspot.com/2011/06/shell-script-to-find-prime-factors-of.html

Leave a Reply