# Multiply digits within a number with each other

I have list of numbers, and I want to multiply the digits within each number with each other; e.g. for the number 1234 it is 1 X 2 X 3 X 4 = 24

E.g. the following input

``````7675342567
098765342567
1234567890
0987654
234567
8765678
98
0999
09876543
345678
876543
87654
``````

needs the following result:

``````7408800
0
0
0
5040
564480
72
0
0
20160
20160
6720
``````

How should I proceed?

• Sorry but this is not a scripting service. If you do not know any shell scripting, you'd start learning. – andcoz Oct 8 '18 at 15:39
• @andcoz i don't like programming and it is not my hobby, I have problem and I need help what is wrong with that? – Sydney Oct 8 '18 at 15:40
• Sydney: The problem is that this site teaches people programming. If you don't care about the "how", pay someone to solve the problem for you. – choroba Oct 8 '18 at 15:50
• "what is wrong with that?" is a complex question, please read this: How do you feel about “GIVE ME TEH CODEZ” questions? – andcoz Oct 8 '18 at 15:52
• Homework: policy proposal – Peter Mortensen Oct 8 '18 at 19:11

You can do it this way:

``````<file sed 's/./&*/g;s/*\$//' | bc

7408800
0
0
0
5040
564480
72
0
0
20160
20160
6720
``````

With GNU `sed`, that can be simplified as:

``````<file sed 's/./*&/2g' | bc
``````

Strictly within bash, assuming you don't overflow beyond 9 quintillion and change (9,223,372,036,854,775,807),

``````while IFS= read -r
do
res=1