Question

Shell Programming Question: Write a shell program that reads a set of integers {125, 0, 122,...

Shell Programming Question:

Write a shell program that reads a set of integers {125, 0, 122, 129, 0, 117}, and then prints a set of integers {125, 122, 129, 117}.

Tips: Remove zeros

**Write comments for code

Homework Answers

Answer #1

echo "Enter the array";
# To read the input from keyboard
read n
IFS="," #delimiter declartion.
a=0
# Declared new empty array for storing the result which does not contain the zero in it.
declare -a resultArray=()

#Splitting the string using delimiter ','
read -ra IN <<<"$n"

#Iterating the array one by one to find out the zero
for i in "${IN[@]}";
do
  
#Comparing the each element of array with zero if not equal to zero then storing into new array i.e resultArray
if [[ $i != $a ]] #Converting string element into integer
then
resultArray+=($i)
fi
done
#Printing the resultant array without zero in it
echo "${resultArray[*]}"
  

Know the answer?
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
Similar Questions
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
I'm working on the below problem: For this question, you are to write a program that...
I'm working on the below problem: For this question, you are to write a program that reads the data in the file state_satscores_2004.txt. Each line of this file has name of a state, mean Verbal SAT score, and mean Math SAT score. After reading the data, a. Print the state with the highest mean Verbal SAT score b. Print each state that has a mean Math SAT score greater than 500 Submit the code and the output from your program....
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT