Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion q1.sh
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
This is q1 answer
#!/bin/bash
#q1a
cat books/aliceinwonderland.txt | awk '{print NR}' | tail -1
3325

#q1b
cat books/aliceinwonderland.txt | awk '/ Alice / {print NR,NF, /bin/bash} ' | awk '{print NR}' | tail -n 1
155

#q1c
cat books/aliceinwonderland.txt | awk '{ for (i=1; i<=NF; i++) c[]++} END { for( w in c) if (c[w]==1) print w } '
3860

#q1d

cat books/aliceinwonderland.txt | awk '{for( i=1; i<=NF; i++) print } ' | sort | uniq -c | sort -n | tail -6
459 of
569 a
662 and
669 to
849
1400 the

#q1e
words=$(cat books/aliceinwonderland.txt | awk '{ words+=NF } END { print words} ')
char=$( cat books/aliceinwonderland.txt | awk ' {for (i=1; i<=NF; i++) chars+=length($i) } END { print chars} ')
result=$((char/words))
echo $result
4
20 changes: 20 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

#q2a
cat books/sherlockholmes.txt | sed -n '/Sherlock\|Holmes/p' | awk '{print NR, /bin/bash}' | cut -f 1 -d | tail -1
463

#q2b
cat books/sherlockholmes.txt | sed -n '/Sherlock\|Holmes/p' | grep Holmes |Sherlock | wc -l
220


#q2c
cat books/sherlockholmes.txt | sed 's/^.\{70,\}$/Long Line/'

#q2d

cat books/sherlockholmes.txt | sed 's/[A-Z][a-z]*\([[:space:]][A-Z][a-z]*\)\{1,\}/Omer/'

#q2e
cat books/sherlockholmes.txt | sed -E 's/\(([^)]*)\)/[\1]/g'