Problem 1 a) head -‐10 names.txt >> group1.txt b) ls –a /usr/local | wc -‐l > allfiles.txt
c) ls –R | sort –r >> result.txt d) tail -‐100 /opt/passwordList.txt | sort –d |uniq –c | sort –n | head -‐3 > /opt/pw/commonPasswords.txt Problem 2 a) The purpose of wildcards is to save on typing by representing many things. It allow you to use a single character to represent 1 or more characters that could be anything. It is a basic pattern that can match 1 or more characters. Examples include ‘*’ and ‘?’ b) ls r* | *.jpg c) ls *sample* d) ls ?.py
Problem 3 a) Regular expression is essentially a pattern that you can specify to perform advanced searching. You specify the pattern, and anything that matches the pattern will be returned. b) grep is used for searching using regular expressions, while egrep is an enhanced version of grep that adds extended regular expressions (contain more syntax for defining even more powerful regular expressions). c) Egrep ‘(^goodbye)|(^later)|(^farewell)’ usernames.txt d) ‘Unix is$’ ‘[abc]$’ ‘file [0 1 2 3 4 5 6 7 8 9][0 1 2 3 4 5 6 7 8 9][0 1 2 3 4 5 6 7 8 9]’ ‘^[^x]*x?[^x]*$’ ‘a*b?*c’
Problem 4 a) AWK is essentially a type of programming language that focuses on text data processing. It is useful for processing lines of data using a powerful syntax. b) awk –f processNumbers.awk c) awk ‘END {print NR}’ total.txt awk ‘{print $ (NF-‐1)}’ second.txt awk ‘NF >2 {total +=$4} END {print total}’ price awk ‘{temp=$1;$1=$NF; $NF=temp; print $0} END {print “Finished!”}
Problem 5 a) awk –F’,’ ‘{print $8}’ data.csv b) cut –d, -‐f8 data.csv c) cut –d: -‐f5 records
d) cut –d: -‐f5 | cut –c3 e) cat names.txt | tr ‘[a-‐z#]’ ‘[A-‐Z-‐]’ > names2.txt
Problem 6 vi editor is a screen editor which is available on mostly all Unix systems. vi has a modal interface. vi is a fast and powerful editor. vi has no menus but instead uses combinations of keystrokes in order to accomplish commands. vi commands are case sensitive – lowercase and uppercase command letters do different things. Also, vi is not displayed on the screen when you type them.
Like vi, emacs is a screen editor. However, emacs is not an insertion mode editor, meaning that character typed in emacs is automatically inserted into the file, unless it includes a command prefix. One other distinction between emacs and vi is that emacs allows you to edit several files at once. The window for emacs can be devided into several windows, each of which contains a view into a buffer. Each buffer typically corresponds to a different file.
Nano