Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. [20 points] Write a shell script called fixCprogram.sh which looks up every c

ID: 3917864 • Letter: 1

Question

1. [20 points] Write a shell script called fixCprogram.sh which looks up every c file in the current directory for the strings printf or fprintf. If found, the script adds the statement #include at the beginning of the file but only if it doesn't already have it included. Record a screen shot which shows the result 2. [10 points] Use awk to display all files and directories in current directory that has names longer than 6 characters. Record a screen shot which shows the result. 3. [10 points] Use awk to display from /etc/passwd a list of users and their shells for those using the Korn shell or Bash. Record a screen shot which shows the result. 4. [20 points] Write a perl script called characterline.pl that accepts a string from the keyboard and then prints each character of the string on a separate line. Record a screen shot which shows the result 5. [20 points] Write a perl script called weekdays.pl that populates an array named weekday from the string SunMonTueWedThuFriSat, and then prints each day in uppercase. Record a screen shot which shows the result 6. [20 points] Write a perl script (printReverse.pl) to take a string as an input parameter, and print the string in reverse. For example if the input string is "12 234 abcd" the output should be “dcba 432 21". Record a screen shot which shows the result

Explanation / Answer

clear

grep -l -e "printf" -e "fprintf" *.c > temp.txt

#grep
# -l, --files-with-matches
# Suppress normal output; instead print the name of each input
# file from which output would normally have been printed.

# -e PATTERN, --regexp=PATTERN
# Use PATTERN as the pattern. This can be used to specify
# multiple search patterns


for i in `cat temp.txt`
do
sed '1i#include<stdio .h=".h">' $i > temp2.txt
cat temp2.txt > $i
echo "Successfully Added..."
done

# sed i :
# -i[SUFFIX], --in-place[=SUFFIX]
# edit files in place (makes backup if extension supplied)


# sed l :
# -l N, --line-length=N
# specify the desired line-wrap length for the `l' command
</stdio>