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: 16 additions & 0 deletions Q1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

### A
awk ' {print NR} ' aliceinwonderland.txt | tail -1

### B
awk '/ Alice / {count ++} END {print count}' aliceinwonderland.txt

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

### D
awk '{for (i=1; i<=NF; i++) count[$i]++ } END { for (word in count) print word, count[word] }' aliceinwonderland.txt | sort -k2n | tail -5

### E
awk '{for (i=1; i<=NF; i++) count[$i]++ } END { for (word in count) print word, count[word] }' aliceinwonderland.txt | awk ' {sum_chars += length($1) * $2; total_words += $2} END { print sum_chars / total_words}'
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
awk ' {print NR} ' aliceinwonderland.txt | tail -1

### B
awk '/ Alice / {count ++} END {print count}' aliceinwonderland.txt

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

### D
awk '{for (i=1; i<=NF; i++) count[$i]++ } END { for (word in count) print word, count[word] }' aliceinwonderland.txt | sort -k2n | tail -5

### E
awk '{for (i=1; i<=NF; i++) count[$i]++ } END { for (word in count) print word, count[word] }' aliceinwonderland.txt | awk ' {sum_chars += length($1) * $2; total_words += $2} END { print sum_chars / total_words}'