What line of code needs to be inserted into the script below where indicated to get the result expected when the script below is run?Notes:The external text file data.txt contains the following single line of text:John,25,Mary,36,Jane,50,Andy,unknown,Carrie,32The output to the terminal should be:JohnMaryJaneAndyCarrieBash Script:#!/bin/bashcnt=0# What code would need to go herefor i in `cat data.txt`; do ((cnt++)) if [[ $(($cnt % 2)) -gt 0 ]]; then echo "$i" fidoneexit 0Group of answer choicesIFS=" "IFS=";"IFS=","IFS="\n"
Question
What line of code needs to be inserted into the script below where indicated to get the result expected when the script below is run?Notes:The external text file data.txt contains the following single line of text:John,25,Mary,36,Jane,50,Andy,unknown,Carrie,32The output to the terminal should be:JohnMaryJaneAndyCarrieBash Script:#!/bin/bashcnt=0# What code would need to go herefor i in cat data.txt; do ((cnt++)) if [[ cnt % 2)) -gt 0 ]]; then echo "$i" fidoneexit 0Group of answer choicesIFS=" "IFS=";"IFS=","IFS="\n"
Solution
The line of code that needs to be inserted into the script is:
IFS=","
This sets the Internal Field Separator (IFS) to a comma, which is the delimiter in the data.txt file. This means that the 'for' loop will iterate over each comma-separated value in the file. Since the names are the odd-numbered items in the list, and the 'if' statement only echoes these, only the names will be printed to the terminal.
Similar Questions
What line of code needs to be inserted into the script below where indicated to get the result expected when the script below is run?Notes:The external text file data.txt contains the following single line of text:John,25,Mary,36,Jane,50,Andy,unknown,Carrie,32The output to the terminal should be:JohnMaryJaneAndyCarrieBash Script:#!/bin/bashcnt=0# What code would need to go herefor i in `cat data.txt`; do ((cnt++)) if [[ $(($cnt % 2)) -gt 0 ]]; then echo "$i" fidoneexit 0Group of answer choicesIFS=" "IFS=";"IFS=","IFS="\n"
What will the last line of output to the terminal be when the script below is run?Note: You response must be precisely what will be printed to the terminal to be marked correct.#!/bin/bashdeclare -a datadata=(John Peter Mary Jane Andy Carrie)for i in "${data[@]}"; do if [[ ${#i} -gt 4 ]]; then echo "$i" fidoneexit 0
Given the following script code:1 Sort Stations.txt > SortCount.txt2 echo "The number of words in the file:" >> SortCount.txt3 cat Stations.txt | wc -w >> SortCount.txt4 echo "The number of line in the file:" >> SortCount.txt5 cat Stations.txt | wc -l >> SortCount.txtWhich line of code will cause error when running the script? Assume that file Stations.txt exists and is accessible.Group of answer choicesLine 5There is no error in the scriptLine 3Line 1
How do you comment out multiple lines in a shell script?
Fill the code to open the text file data_science in read mode using with statement and to print all the statements within the file. (Use single quotes and do not leave the blank spaces)
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.