#!/bin/bash
mkdir Dictionary
for litera in {A..Z}; do
cd Dictionary
echo > $litera.txt
cd ..
awk '{
for(i = 1; i <= NF; i++) {
print $litera;
if(match(tolower($i), "^$litera")) {
print $i;
}
}
}' myfile | sort > Dictionary/$litera.txt
done exit 0
myfile has the text: I have apples
The problem is that in the awk method $litera = I have apples
I want it to have: I, h, a ,v , e etc.
What I essentially want is to take all the words from myfile and putem them in the Dictionary folder, each word on its corresponding file.
Output:
A.txt : apple
I.txt: I
H.txt: have
The rest will be empty.