Question

In: Computer Science

this lab, you will write a shell script, called compare_cols.sh. This program should Read a CSV...

this lab, you will write a shell script, called compare_cols.sh. This program should

  • Read a CSV file from standard input (STDIN).
    • Note that in general, CSV files may contain quoted fields with embedded newlines. But for this assignment you can assume that there are no fields with embedded newlines, and therefore each new line represents a new row of the CSV file.
  • Print a single number (integer) to standard output (STDOUT): the count of the lines in the CSV file for which the first word occurring in column 3 of the CSV also occurs as a word in column 5 of the CSV.
    • For the purposes of this assignment, words are considered to be sequences of non-space characters delimited on either side by spaces or by the beginning/end of the text string.
    • Whitespace surrounding the integer output will be ignored for scoring.For example, in the following CSV row, the word "six" occurs at the beginning of column 3, and also as a word in column 5:
      one two three,four five,six seven,eight,nine six ten,eleven

Bashscript

Solutions

Expert Solution

Answer) # indicates the comment

echo "Enter the file name"
#read the file from standard input
read fn
#take a counter for line count
c=0
#start the while loop to read every line from the file
while read -r l1
do
#extract the first word of column3 from the line
col3=`echo $l1|cut -d "," -f 3|cut -d " " -f 1`
#extract column5 from the line
col5=`echo $l1|cut -d "," -f 5`
#search col3 from col5
echo $col5|grep $col3 >/dev/null
#check if found then increase c by 1
if test $? -eq 0
then
c=`expr $c + 1`
fi
#loop end and suppy the file name
done < $fn
#display the output of the count
echo $c

Screenshot


Related Solutions

Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the...
Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the files from two named directories into a new third directory. Timestamps must be preserved while copying files from one directory into another. Task Requirements Three directory names must be supplied as arguments to your script when it is executed by the user. In the beginning of your script you need to check that the first two directory names provided (e.g. dir1 and dir2) exist...
Please write a shell script called "myfilechecking" to determine whether a file belongs to one of...
Please write a shell script called "myfilechecking" to determine whether a file belongs to one of the following categories: A directory; A scrip file (readable and executable); An executable file (not readable but executable, such as a.out); A regular ascii file (only readable, such as a C source code file); The file cannot be recognized. Your script should display the corresponding information based on the category of the file; The file name should be provided along with your script invocation,...
For this week’s lab assignment, you will write a program called lab9.c. You will write a...
For this week’s lab assignment, you will write a program called lab9.c. You will write a program so that it contains two functions, one for each conversion. The program will work the same way and will produce the same exact output. The two prototypes should be the following: int btod(int size, char inputBin[size]); int dtob(int inputDec); The algorithm for the main() function should be the following: 1. Declare needed variables 2. Prompt user to enter a binary number 3. Use...
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
C++ Funcion For this lab you need to write a program that will read in two...
C++ Funcion For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using Euclidean algorithm) to a file. You will also need to demonstrate using ostream and ostringstream by creating 2 functions to output your print heading: one that uses ostream and the other uses ostringstream. Using ostream and ostringstream Write two PrintHeader functions that will allow you to output to the screen and to an...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell script to take a directory as an argument and display the contents of that directory (10pts) Write a shell script that takes any command as a parameter and displays help on that command (e.g. the result of the execution of man <command>). (10pts) Write a shell script that requires two file names as parameters and copies content of one file into another without asking...
Write a Java program to read in the 10 numbers in the example file Book1.csv provided...
Write a Java program to read in the 10 numbers in the example file Book1.csv provided above. The program should sum all the numbers, find the lowest number, find the highest number, and computer the average. Upon completion of the processing, the program should write a new text file named stats.txt with the information found in the following format where xxx represents a number calculated above. The sum of the numbers is: xxx The lowest number is: xxx The highest...
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT