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

CS3423 Midterm Sample Problems 1. Chmod - rec wk2 a: Using symbolic modes, updat

ID: 3596093 • Letter: C

Question

CS3423 Midterm Sample Problems

1. Chmod - rec wk2
a: Using symbolic modes, update all files in the directory so the owner has execute access to them
b: Using symbolic modes, update all files in the directory ending with .jar to add execute access for the owner and set group and other to have only read and execute access

2. file name pattern matching - rec wk 2
a: List all files beginning with any number between 0 and 4.
b: List all files with either the word “input” or “output” in the filename. c: List all files beginning with “A” which end with an extension.

3&4 find/grep rec wk4, notes
a. List files containing "printf" in the current directory only.
what if we wanted to look in subdirectories?
b. List files which owned by "west" with a size less than 800 kb

5. BASH - rec wk 3, pgm1, notes
a. Create a shell script, rev5, which can take a file’s contents from stdin with each text line containing a low temperature and a high temperature. We want to count:

the number of hot days (low temperature is hotter than 80 degrees)

the number of cold days (high temperature is less than 60 degrees)
the number of weird days where the low temperature is hotter than 80 degrees, but the high temperature is the same as the low temperature.
Print each of those counts.

Invoking command: $

Bash script:
b. Repeat, but pass the file as an argument.

6. SED - rec wk5, pgm2, notes
Create a sed script which replaces all instances of “<h1>” or “<h2>” to “<strong>” and all
instances of “</h1>” or “</h2>” to “</strong. Also include the command to run the script called rec4-3.sed for a file named file2.html (contents below) and print output to file2Fixed.html

'<!-- file2.html -->

'<h1>title</h1>

'<h2>subtitle</h2>

'<footer>

footer text

'</footer>

'<p>some text</p>

Invoking command:

$

7. AWK - rec wk 6, pgm3, pgm4, notes

Consider this data in revIn.txt:
rslavin,120,Aug 28 2017,assignment1.zip

rslavin,132450,Aug 28,13:29 bigfile.zip

clark,12,Aug 28 13:29,file1.txt

rslavin,540,Aug 28 13:29,file2.txt

clark,708,Aug 28 13:29,file3.zip

rslavin,70,Aug 28 13:30,input

rslavin,70,Aug 28 13:30,more files

rslavin,65,Aug 28 13:30,output

rslavin,12,Aug 28 13:31,someScript.sh

rslavin,673,Aug 28 13:29,test data.zip


Create an awk script which takes that information and counts the number of files for each owner (1st column). For one user passed as an argument, also print the total bytes (the size is in the 2nd column).

Sample output:
clark 2
rslavin 8
total bytes for clark = 720

Invoking command: $
Script:

8. PERL
a. Show code to validate a course number (e.g., CS3423, MAT1214) which is in the variable $course. It must begin with either two or three uppercase alphabetic characters followed by 4 digits. The first digit must be between 1 and 6. The last digit must be between 1 and 4. The other two digits can be any digit. Also, place the department in $dept and the number in $num.

b. For each of the specified values and patterns, what are the results? show the value of $1 or NP (not populated) if the pattern didn't match. Show spaces as .
  

m/(the.*s)/

m/([a-z]*)s/

m/[^aeiou]+s([aeiou]*)/

m/s(w*)/


c. Use Perl to do that same awk problem. Pass in the file name and user name.

$ perl rev8c.pl revIn.txt clark

Seq Value Pattern    $1 1 "the last of the best"

m/(the.*s)/

2
"the last of the best"

m/([a-z]*)s/

3 "the last of the best"

m/[^aeiou]+s([aeiou]*)/

4 "the last of the best"

m/s(w*)/

Explanation / Answer

NOTE:As per Chegg answering guidelines we are supposed to answer the first four questions in the list of questions given. Also i did not get sufficient time to answer other set of questions provided. So could you please raise them as separate question. I have answered the first 4 questions in the list of questions provided.

Please check the answers below and let me know if you have any questions. I will acknowledge back with a response within 24 hours.

1. Chmod - rec wk2
a: Using symbolic modes, update all files in the directory so the owner has execute access to them
Ans)

command:- chmod u+x *
The above command will set execute permission to the owner for all files in the directory.

b: Using symbolic modes, update all files in the directory ending with .jar to add execute access for the owner and set group and other to have only read and execute access
Ans)

command:- chmod u+x go+rx *.jar
The above command will set execute permission to all files with extension .jar and read, execute permission to group and other for all files ending with extension .jar.

2. file name pattern matching - rec wk 2
a: List all files beginning with any number between 0 and 4.
Ans)

command:- ls|grep '^[0-4]'
The above command will list all the files in current directory. Whereas grep command will check if the filenames are beginning with any number between 0 to 4.

b: List all files with either the word “input” or “output” in the filename.
Ans)

command:- ls|egrep 'input|output'
The above command list all the files in current directory. Then it searches for files which has either input or output in the filenames.

c: List all files beginning with “A” which end with an extension.
Ans)

command:- ls |grep '^A.*.'
The above command list all files in the current direcory. Then it searches for filenames which starts with A and has an extension. Note that '.' is used in grep to indicate if the filename got an extension.

3&4 find/grep rec wk4, notes
a. List files containing "printf" in the current directory only.
Ans)

command:- find . -exec grep printf {} ;
The above command finds all the files in the current directory. Then on each file it runs grep command to check if the file contents contain printf.

what if we wanted to look in subdirectories?
b. List files which owned by "west" with a size less than 800 kb
Ans)

command:- find -user west -size -800k
The above command finds all finds all the files with 'west' as the owner using -user option and verifies the file size is less than 800kb using -size command.