تم الحل ✓
categoryهندسة الحاسبات
schoolبكالوريوس
event_available2026-07-15
السؤال
Transcribed Image Text:
UNIX Shell Scripts
Each problem is worth 10%, for a total of 60%.
Problem 1
Write a script named isearch to allow users to input a file name and a word/pattern.
Search the file for the word/pattern and display the lines that contain the word/pattern on
the standard output. If the word/pattern is not found, display a message.
indigo 20% isearch
Enter the file name: phone_book.txt
Enter the word to search for: from
Case-sensitive (y/n)? n
Nikola Sandic
ROB Oxley
(647) 209-7932 friend from work
(416) 723-8759 friend from university
If the word/pattern is not found, display a message.
Word 'from' not found.
Problem 2
Write a script named icount to allow users to input a file name and display on the
standard output the number of lines, words or characters in the file.
indigo 21% icount
Enter the file name: phone_book.txt
Count lines, words, characters or all three (1, m, c, a)? b
Invalid option
Count lines, words, characters or all three (1, m, c, a)? m
File 'phone_book.txt' contains 125 words.
Problem 3
Write a script named allfiles to allow a user to list all (ordinary) files in the current
directory, one per line, but not the sub-directories in the current directory. (Note:
command '1s' displays all files and directories.)
indigo 22% allfiles
lab3a.c
lab3b.c
lab3b_out.txt
Problem 4
Write a script named fdisplay to allow a user to input a file name and an option to
display the content of the file (entire file, entire file one page at a time, first 10 lines, last 10
lines). Display the content of the file as the user specifies. If the user enters an invalid
option, display an error message and ask for a correct option.
EECS 2031 - Assignment 2
indigo 23% fdisplay
Enter the file name: phone_book.txt
Enter option (e, p, f, 1): a
Invalid option
Enter option (e, p, f, 1): p
# File is displayed one page at a time
Problem 5
Write a script named doublesp to allow a user to input an input and an output file name.
Copy the content from the input file to the output file, adding a blank line between every
two lines of the input file (double spacing). If the output file exists, display the message
shown below. If the user answers yes then append the output to the file. If the user
answers no, exit and do nothing (i.e., do not overwrite an existing file).
indigo 24% doublesp
Enter input file name: phone_book.txt
Enter output file name: outfile.txt
File 'outfile.txt' exists.
Append to it (y/n)? y
Problem 6
Write a script named addlines to allow a user to enter an input and an output file name.
Copy the content from the input file to the output file, line by line, adding a line number at
the beginning of each copied line. Add a space after the colon before copying the line.
If the output file exists, display a message as above. If the user answers yes then append
the output to the file. If the user answers no, exit and do nothing.
indigo 25% addlines
Enter input file name: phone_book.txt
Enter output file name: outfile.txt
indigo 26% cat outfile.txt
1: Ray Szeto
(416) 564-6786 friend
2: alex johnson
(416) 555-1234 family doctor
3: Tom Podstawka
(647) 579-3854
dentist
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.