0
#!/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.

4

1 回答 1

1

This can be made to work using gawk or awk as follows:

$echo "I have an apple"| gawk -F "" '{print $3}'
h

$echo "I have an apple"| awk -F "" '{print $3}'
h

$echo "I have an apple"| awk'{split($0,array,"")} END{print array[3]}'
h
于 2013-05-12T15:22:11.710 回答