Question

Write an awk command that will calculate the sum of all digits in a specified file....

Write an awk command that will calculate the sum of all digits in a specified file. So the number 251 would be 2+5+1, it would do this for all numbers found in a file providing just sum as the output.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Use the below command to calculate the sum of the digits of a number:

awk -F '' '{ sum = 0; for(i=1; i<=NF; i++) sum += $i; print "sum " sum }' file
Add a comment
Know the answer?
Add Answer to:
Write an awk command that will calculate the sum of all digits in a specified file....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an awk script to print just the name and size of ordinary files (do not...

    Write an awk script to print just the name and size of ordinary files (do not include directories), one on each line. The output must be aligned as shown in the example below. First, analyze a typical output of the ls -l command to see what differentiates an ordinary file from a directory and which fields contain the file name and size information. Then, determine what the field separator is and whether the default field separator of awk will work,...

  • QUESTION 1 From YOUR home directory, execute a find command string that will locate the file...

    QUESTION 1 From YOUR home directory, execute a find command string that will locate the file called resolv.conf. Include the -exec flag in the find command to cat the file to the screen. Begin your find search from the letc directory Select the correct find command string below that will accomplish this. find /etc-name 'resolv.conf -cat D find /etc-name 'resolv.conf -exec cat 0 find. -name 'resolv.conf -exec cat 0\ find /-name 'resolv.conf' -exec cat 0 QUESTION 2 What find command...

  • Write an awk script that prints a list of all the words in an input file along with the number of...

    Write an awk script that prints a list of all the words in an input file along with the number of times each word appears. Write an awk script that prints a list of all the words in an input file along with the number of times each word appears.

  • Write a C program that determines the sum of the decimal digits that appear in the...

    Write a C program that determines the sum of the decimal digits that appear in the command line arguments (excluding argv[0]) of the main function. The sum should be zero if there are no command line arguments following argv[0], or if the command line arguments following argv[0] do not include any decimal digits. Example If the command line arguments (following argv[0]) were 7M3 3DoorsDown Sum41 U2 The4Seasons Maroon5 TheB52s then the sum would be 7 + 3 + 3 +...

  • Write an egrep command that prints out all the valid ID numbers in the file lines.txt....

    Write an egrep command that prints out all the valid ID numbers in the file lines.txt. A valid ID number has the following rules: It starts with a hash mark (#) followed by 3 digits, one dash (-) and another group of 5 digits. There is an optional letter in front (before the hash mark) that can be from A to F (including A and F). NOTE: Look at the lines.txt file for examples of valid and invalid ID numbers....

  • (Java Please) Sum of Digits Write a program that will sum the digits of a number...

    (Java Please) Sum of Digits Write a program that will sum the digits of a number input by the user. For example, if the user enters the number 1234, the sum of the digits will be 10 (1 + 2 + 3 + 4 = 10). The user will enter a number with at least 4 digits (greater than 1000). That value will be sent to a method which will return the sum. Sample Output 1: SUM OF DIGITS -------------...

  • a) Write a one-line sed command that will replace all multiple spaces in a file called...

    a) Write a one-line sed command that will replace all multiple spaces in a file called names.txt (this is an arbitrary file that you may create yourself) by only one space. b) Consider the following file called system.txt: 1  2  3  4 5  6  7  8 9  He 11 Hg Ts H  15 Be 17 Mc Li 20 Write a one-line sed command that replaces the second number in every line with the string “system”, without the quotes. For example,...

  • 7. Write a command that redirects all chrome processes to a file name process.txt. Write a...

    7. Write a command that redirects all chrome processes to a file name process.txt. Write a command to output the content of process.txt file. 8.Write a command that redirect (add) all processes containing the word “host” to process.txt file above. 9.Write a command that will ask users about their location (“Where do you live?”). The command should read the input from a user and store it in a variable “$location”. Use another command to output the user’s response. 10.Write a...

  • In a linux command line Give AWK commands for accomplishing each of the following: Print the...

    In a linux command line Give AWK commands for accomplishing each of the following: Print the 2nd last field (the field directly before the last field) of each line from a file named 'last.txt' Assume you have a file called 'names' that contains a list of people, one person per line. Also, assume that on each line the 3rd field on that line contains the age of the person. Some of the people do not have an age listed, and...

  • 1) Write a C program that displays all the command line arguments that appear on the...

    1) Write a C program that displays all the command line arguments that appear on the command line when the program is invoked. Use the file name cl.c for your c program. Test your program with cl hello goodbye and cl 1 2 3 4 5 6 7 8 and cl 2) Write a C program which displays the sum of the command line arguments. Hint: use sscanf to convert the decimal arguments (which are strings) to binary numbers that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT