Question 3. (20 marks) Write a short but well structured Bash script that, given
ID: 3719082 • Letter: Q
Question
Question 3. (20 marks) Write a short but well structured Bash script that, given the name of a file as an command line argument, reads the file name and creates a new file containing only those lines in which there is a single English word (could be a number or punctuation mark). Here is an example of the input file. This is a special text file There are 60 students enrolled in this course. TAB][SPACE] Nearly half of that number of students are in the Faculty of HES The rest of them are from Faculty-of-BLA. Note: 1. Well structured' means the script must have the error checking and robustness checking. 2. The composite word linked by dash is regraded as one word.Explanation / Answer
#input file from commandline
inputfile=$1
#reading input file line by line
while read LINE
do
#counting words in a line
STRLENGTH=`echo -n $LINE | wc -w`
if [[ STRLENGTH -eq 1 ]]
echo $LINE >>"newFile.txt"
done <$inputfile
Note:[Please comment back in case of any query. Happy to help you]
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.