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
17 changes: 16 additions & 1 deletion q1.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
This is q1 answer
#!/bin/bash

--a = 3325
awk 'END {print NR}' aliceinwonderland.txt

--b = 395
awk '{for (i=1; i<=NF; i++) if ($i ~ /Alice/) count++} END {print count}' aliceinwonderland.txt

--c
awk '{for (i=1; i<=NF; i++) freq[$i]++} END {for (word in freq) if (freq[word] == 1) print word}' aliceinwonderland.txt

--d
awk '{for (i=1; i<=NF; i++) freq[$i]++} END {for (word in freq) print freq[word], word}' aliceinwonderland.txt | sort -nr | head -5

--e = 4.37
awk '{for (i=1; i<=NF; i++) {total += length($i); count++}} END {print total/count}' aliceinwonderland.txt
15 changes: 15 additions & 0 deletions q2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
--a = 463
sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l

--b = 12797
sed -n 's/Sherlock/&\n/g; s/Holmes/&\n/g; p' sherlockholmes.txt | wc -l

--c
sed 's/^/Hello: /' sherlockholmes.txt

--d
sed -E 's/\b[A-Z][a-z]+\s[A-Z][a-z]+/Arik Apl/g' sherlockholmes.txt

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