Things to keep in mind: Read the requirement carefully, and clarify with the instructor if it's not clear.
Solution: Use command grep -f phone.grep file.txt to match phone numbers in file.txt. The phone.grep (see here) stores the list of patterns as follows.
[^0-9][0-9]\{10\}$ [^0-9][0-9]\{10\}[^0-9] [^0-9][0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}$ [^0-9][0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}[^0-9] [^0-9][0-9]\{3\}\,[0-9]\{4\}$ [^0-9][0-9]\{3\}\,[0-9]\{4\}[^0-9] [^0-9][0-9]\{3\}\-[0-9]\{4\}$ [^0-9][0-9]\{3\}\-[0-9]\{4\}[^0-9] [^0-9]*\([0-9]\{2\}\)\([0-9]\{3\}\)[0-9]\{3\}\,[0-9]\{4\}$ [^0-9]*\([0-9]\{2\}\)\([0-9]\{3\}\)[0-9]\{3\}\,[0-9]\{4\}[^0-9] [^0-9]*\([0-9]\{2\}\)\([0-9]\{3\}\))?[0-9]\{3\}\-[0-9]\{4\}$ [^0-9]*\([0-9]\{2\}\)\([0-9]\{3\}\))?[0-9]\{3\}\-[0-9]\{4\}[^0-9] [^0-9]*[0-9]\{2\}\,[0-9]\{3\}\,[0-9]\{3\}\,[0-9]\{4\}$ [^0-9]*[0-9]\{2\}\,[0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}[^0-9] [^0-9]*[0-9]\{2\}\,[0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}$ [^0-9]*[0-9]\{2\}\,[0-9]\{3\}\,[0-9]\{3\}\,[0-9]\{4\}[^0-9]
wget http://storm.cis.fordham.edu/~zhang/cs3130/Codes/wordlist.txtThe wget command retrieves a resource (wordlist.txt) specified by an URL, and stores it under your current directory. Write a bash script that finds out words matching the following patterns (one grep command per pattern):
Solutions:
echo "6 letters palindrome" grep '\(.\)\(.\)\(.\)\3\2\1' wordlist.txt
echo "Words no more than five letter long" grep -v '......' wordlist.txtOr
grep -E '(^.$)|(^..$)|(^...$)|(^....$)' wordlist.txt
echo "words that contains letters c, a, t in them, in this order (can be separate with other letters), e.g., chat, catch, ...." grep 'c[a-z]*a[a-z]*t' wordlist.txt
Solution: We create a sed script, named rmcnt.sed as follows, make the file executable:
#!/bin/sed -f ## remove one-line comments from C/C++ code /^[^'"]*\/\// s/\/\/.*$/ /gAnd then we use the following command to remove comment from C/C++ code:
rmcnt.sed sample.cpp
Solution:
ls -l | ## Get the long listing tr -s ' ' ' ' | ## replace mulitple spaces with a single space cut -d ' ' -f 5,9 ## using space as field delimiter, choose the 5th, 9th fields
Solution:
cat *.cc *.cpp | wc -l
$ checkUser zhang zhang 2 login window; login shell is /bin/bashYou can find the number times the user log in using information provided by command who. You can find the login shell used by the user by looking up file /etc/passwd. Hint: You need to figure out how to cut and compose the above output.
Solution: The following is the CheckUser script:
#!/bin/bash # CheckUser: check how many login windows a user has, and the shell the user uses if [ $# -ne 1 ] then echo "Usage: CheckUser"; exit 1; fi echo -n "$1 " echo -n `who | grep $1 | wc -l` echo -n " login window;" echo -n "login shell is " grep ^$1 /etc/passwd | cut -d ':' -f 7
What to submit: Please submit only your scripts. Just use command cat to merge all scripts into one file named lab3.txt, and then follow the instruction here to submit the lab3.txt file to me.