Write a bash script named buildList that generates lists by selecting the specif
ID: 3604054 • Letter: W
Question
Write a bash script named buildList that generates lists by selecting the specified column of a spreadsheet stored in CSV format. The script should be invoked as BuildList where "column" is the desired column number, and any remaining arguments are input files. The output should be a single line for each input file, consisting of the filename with directory and extension .csv removed, and a comma-separated list built from the specified column of the spreadsheet. The first line of the spreadsheet is assumed to be column headers, and should be ignored. The script may invoke sed and awk if needed (in fact this is encouraged, because it will make your solution easier). For example:Explanation / Answer
Solution:
script:
This is the script which will extract the specified columns apart from header
#!/bin/bash
a=$#
col=$1
args=("$@")
i=1
while [ $i -lt $a ]
do
printf $(basename ${args[$i]} .csv)": "
cut -d , -f $col ${args[$i]} | sed "1 d" | xargs | sed -e 's/ /,/g'
let "i =i+1"
done
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.