I’ve been trying the week 2 quiz for observers and for the questions about user manuals find that I get answers that aren’t even options to submit! I appreciate this may be because the manuals differ between linx/mac/windows. However, I’d appreciate seeing any code others have written which does seem to work. Or perhaps the instructors could share some model code answers? (I know the assignment isn’t graded, but would still like to be able to understand the answers!)
First Q:
My attempt at counting occurences of pattern within grep user manual is
man grep | grep pattern | wc -l
(output 21 in windows ubuntu, 23 in linux ubuntu)
Second Q:
Using only commands in the Terminal application, create a directory called “week_2”. Within this directory, save the user manuals of the commands “grep”, “cat”, and “ls” to respective files called “grep.txt”, “cat.txt”, and “ls.txt”. Using one line in the Terminal, sort the contents of these three files by the number of lines they contain, in ascending order. What is this order?
Part 1: making files
mkdir week_2
cd week_2
man grep > grep.txt
man cat > cat.txt
man cat > ls.txt
Part 2. I really struggled to get this all on one line.
for f in *.txt; do wc -l $f >> lines.txt ; done
sort -n lines.txt
(output: 71 cat.txt, 71 ls.txt, 671 grep.txt)