Title: Quiz 9 - Regular Expressions
Course: CIS 121: Linux/UNIX I: Fundamentals ~ For IGNITE Review

Q: Display all line from file1 that end in xyz.
A: grep "xyz$" file1 / grep ".*xyz$" file1 / grep 'xyz$' file1 / grep xyz$ file1 / grep '.*xyz$' file1 / cat file1 | grep xyz$ / grep .*xyz$ file1 / cat file1 | grep 'xyz$'
If wrong: A command to display all line from file1 that end in xyz is: grep xyz$ file1

Q: Display all lines from file1 that start with abc.
A: grep "^abc" file1 / grep "^abc.*" file1 / grep '^abc' file1 / grep ^abc file1 / grep '^abc.*' file1 / grep ^abc.* file1 / cat file1 | grep ^abc / grep "^abc.*$" file1 / cat file1 | grep '^abc' / more file1 |grep '^abc' / cat file1 | grep '^abc.*'
If wrong: A command to display all lines from file1 that start with abc. is: grep ^abc file1

Q: Display all lines that start with a digit and end in a lowercase letter in files whose names start with a digit and end in a lowercase letter.  Assume LC_COLLATE=C (Case Sensitivity)
A: grep "^[0-9].*[a-z]$" [0-9]*[a-z] / grep '^[0-9].*[a-z]$' [0-9]*[a-z] / grep ^[0-9].*[a-z]$ [0-9]*[a-z] / cat [0-9]*[a-z] | grep ^[0-9].*[a-z]$ / grep '^[0-9].*[a-z]$' ./[0-9]*[a-z] / sed -n '/^[0-9].*[a-z]$/p' [0-9]*[a-z] / cat [0-9]*[a-z] | grep '^[0-9].*[a-z]$' / grep ^[0-9].*[a-z]$ ./[0-9]*[a-z]
If wrong: A command to display all lines that start with a digit and end in a lowercase letter in files whose names start with a digit and end in a lowercase letter, assuming LC_COLLATE=C (Case Sensitivity) is: grep ^[0-9].*[a-z]$ [0-9]*[a-z]

Q: Display all lines in file1 except for lines that end with a pair of digits.
A: grep -v "[0-9][0-9]$" file1 / grep -v '[0-9][0-9]$' file1 / grep -v [0-9][0-9]$ file1 / grep -v '.*[0-9][0-9]$' file1 / sed /[0-9][0-9]$/d file1 / sed '/[0-9][0-9]$/d' file1 / grep -v ".*[0-9][0-9]$" file1 / grep -v [0123456789][0123456789]$ file1 / cat file1 | grep -v [0-9][0-9]$ / cat file1 | grep -v '[0-9][0-9]$'
If wrong: A command to display all lines in file1 except for lines that end with a pair of digits is: grep -v [0-9][0-9]$ file1

Q: Display only lines 5-9 of file1.
A: sed -n '5,9p' file1 / head -9 file1 | tail +5 / cat file1 | head -9 | tail +5 / tail +5 file1 | head -5 / head -9 file1 | tail -5 / cat file1 | head -9 | tail -5 / cat file1 | sed -n '5,9p' / sed -n 5,9p file1 / sed -n "5,9p" file1 / cat file1 | tail +5 | head -5 / head -9 file1 | tail -5 | more / more file1 | tail +5 | head -5
If wrong: A command to display only lines 5-9 of file1 is: sed -n '5,9p' file1

Q: CHANGE file2 so that all letters are upper case. (Notice, it says CHANGE.)
A: tr '[a-z]' '[A-Z]' < file2 > temp$$; mv temp$$ file2 / cat file2 | tr '[a-z]' '[A-Z]' > temp$$ mv temp$$ file2 / cat file2 | tr '[a-z]' '[A-Z]' > tempfile2 ; mv tempfile2 file2 / cat file2 | tr '[a-z]' '[A-Z]' > temp$$ ; mv temp$$ file2 / cat file2 | tr '[a-z]' '[A-Z]' > temp ; cat temp > file2 / tr '[a-z]' '[A-Z]' < file2 > file2.tmp ; mv file2.tmp file2 / cat file2 | tr '[a-z]' '[A-Z]' > tempfile ; mv tempfile file2 / cat file2 | tr '[a-z]' '[A-Z]' > temp ; mv temp file2 / cat file2 | tr '[a-z]' '[A-Z]' > tmpfile ; mv tmpfile file2 / cat file2 | tr '[a-z]' '[A-Z]' > file2.temp ; cat file2.tmp > file2 / cat file2 | tr '[a-z]' '[A-Z]' > file2temp cp file2temp file2 / cat file2 | tr '[a-z]' '[A-Z]' > tempf2 ; cat tempf2 > file2 / cat file1 | tr '[a-z]' '[A-Z]' > temp$$ ; mv temp$$ file1 / cat file2 | tr '[a-z]' '[A-Z]' > file2x mv file2x file2 / cat file2 | tr '[a-z]' '[A-Z]' > tempfile2 ; cp tempfile2 file2; rm tempfile2 / cat file2 | tr '[a-z]' '[A-Z]' > tmp ; mv tmp file2 / cat file2 | tr '[a-z]' '[A-Z]' > myjunk ; mv myjunk file2 / cat file2 | tr '[a-z]' '[A-Z]' > temp mv temp file2 / cat file2 | tr '[a-z]' '[A-Z]' > tempf2 cp temp2 file2 / cat file2 | tr '[a-z]' '[A-Z]' > temp2 ; mv temp2 file2 / cat file2 | tr '[a-z]' '[A-Z]' > file2temp ; mv file2temp file2
If wrong: CHANGE file2 so that all letters are upper case: tr '[a-z]' '[A-Z]' < file2 > temp file2

Q: Display file1 with every patter 'cat' change to 'dog'.
A: sed 's/cat/dog/g' file1 / cat file1 | sed 's/cate/dog/g' / sed 's/cat/dog/g' < file1 / sed s/cat/dog/g file1 / sed "s/cat/dog/g" file1 / cat file1 | sed 's/cat/dog/g' | more / more file1 | sed 's/cat/dog/g'
If wrong: A command to display file1 with every patter 'cat' change to 'dog' is: sed 's/cat/dog/g' file1

Q: Display the line in file1 that occurs the most times.
A: sort file1 | uniq -c | sort -nr | head -1 / sort file1 | uniq -c | sort -n | tail -1 / cat file1 | sort | uniq -c | sort -n | tail -1 / sort file1 | uniq -c | sort -rn | head -1 / cat file1 | sort | uniq -c | sort -rn | head -1 / cat file1 | sort | uniq -c | sort -nr | head -1 / more file1 | sort | uniq -c | sort -rn | head -1 / cat file1 | sort | uniq -c | sort -r -n | head -1 / sort file1 | uniq -c | sort | tail -1
If wrong: A command to display the line in file1 that occurs the most times: sort file1 | uniq -c | sort -nr | head -1

Q: List the names of all files in or under your home directory taht were created or modified in the last two weeks.
A: find ~ -mtime -14 / find ~/ -mtime -14 / find $HOME -mtime -14 / find ~/. -mtime -14 -print / find ~ -mtime -14 -print / find ~ -type -f -mtime -14
If wrong: List the names of all files in or under your home directory taht were created or modified in the last two weeks: find ~ -mtime -14

Q: Find all lines in all non-hidden files in your current directory that have the pattern "CIS XXX" where each "X" is a digit.  In other words, "CIS 121" or "CIS 286" , etc.  Assume that the letters are uppercase.
A: grep "CIS [0-9][0-9][0-9]" * / cat * | grep 'CIS [0-9][0-9][0-9]' / grep 'CIS [0-9][0-9][0-9]' * / cat ./* | grep 'CIS [0-9][0-9][0-9]' / grep "CIS [0-9][0-9][0-9]" ./* / grep 'CIS [0-9][0-9][0-9]' ./* / grep 'CIS\ [0-9][0-9][0-9]' ./* / grep 'CIS[][0-9][0-9][0-9]' *
If wrong: Find all lines in all non-hidden files in your current directory that have the pattern "CIS XXX" where each "X" is a digit. In other words, "CIS 121" or "CIS 286" , etc. Assume that the letters are uppercase. grep "CIS [0-9][0-9][0-9]" *

Q: Write a command to PRINT ON THE DEFAULT PRINTER the CONTENTS of all files in your home directory that start with "printme". That command should work from anywhere. Do not include your uname in the command. I want the contents of the files, not just a list of names.
A: cat ~/printme* | lp / lp ~/printme* / cat ~/printme* ~/.printme* | lp / lp $HOME/printme* / more ~/printme* | lp