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
16 changes: 15 additions & 1 deletion q1.sh
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
This is q1 answer
#!/bin/bash
#a
awk '{count++} END {print count}' aliceinwonderland.txt

#b
awk '{for(i=2;i<=NF-1;i++) if ($i == "Alice") counter++} END {print counter}' aliceinwonderland.txt

#c
awk '{for(i=2;i<=NF-1;i++) dic[$i]++} END {for(str in dic) if (dic[str] == 1) print str}' aliceinwonderland.txt
#d
grep -o '[A-Za-z0-9]\+' aliceinwonderland.txt | awk '{dic[$1]++} END {for(word in dic) print word,dic[word]}'|sort -k 2 -n | tail -5 | cut -f 1 -d " "

#e
awk '{for(i=1;i<=NF;i++) {sum += length($i); count++}} END {print sum/count}' aliceinwonderland.txt

16 changes: 16 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
#a
sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l

#b
sed -n 's/Sherlock/&/gp; s/Holmes/&/gp' sherlockholmes.txt | wc -l

#c
sed -E 's/(^)/Hello: /g' sherlockholmes.txt

#d
sed -nr 's/([A-Z][a-z]{1,})( [A-Z][a-z]{1,})*/Lihie Kaplun/gp' sherlockholmes.txt

#e
sed 's/(\([^)]*\))/[\1]/g' sherlockholmes.txt