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...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances of a given string within a file. The scripts takes two arguments: the name of the file to check and the string to count occurances of. If the file is not found (or not readable), the script should print the error message Cannot access file and exit with code -1. Otherwise, the script should print the number of occurances of the given string and...
Goal: to write a Python program that will read a playlist from a CSV file and...
Goal: to write a Python program that will read a playlist from a CSV file and display it in the console in the form of a table. https://s3.eu-west-2.amazonaws.com/bb-python-modules/Coursework/CW3/playlist_text_question.html The following is a link to the question. It includes all instruction and a template file (with additional instructions) where the answer must be completed.
C++ The program you write for this lab will read in the number of nodes and...
C++ The program you write for this lab will read in the number of nodes and a binary relation representing a graph. The program will create an adjacency matrix from the binary relation. The program will then print the following : 1. The adjacency matrix 2. Determine if there are any isolated nodes and print them 3. Determine if an Euler path exists and said so. The sample run of the program is as follows. The output should just like...
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,...
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
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT