Being given a text file create a folder that will contain 26
dictionary files as follows:first file contains the words
begining with 'A', alphabetically sorted, the second file with
'B' and so on.

The way I tried to solve it is attached...pls help!

Attachments
{
        	for(i=1;i<=NF;i++)
                        {
                        lit=substr($i,1,1)
                        if((lit == "a") || (lit == "A")) {print"$i" >> "a.txt"}
                        if((lit == "b") || (lit == "B")) {print"$i" >> "b.txt"}
                        if((lit == "c") || (lit == "C")) {print"$i" >> "c.txt"}
                        if((lit == "d") || (lit == "D")) {print"$i" >> "d.txt"}
                        if((lit == "e") || (lit == "E")) {print"$i" >> "e.txt"}
                        if((lit == "f") || (lit == "F")) {print"$i" >> "f.txt"}
                        if((lit == "g") || (lit == "G")) {print"$i" >> "g.txt"}
                        if((lit == "h") || (lit == "H")) {print"$i" >> "h.txt"}
                        if((lit == "i") || (lit == "I")) {print"$i" >> "i.txt"}
                        if((lit == "j") || (lit == "J")) {print"$i" >> "j.txt"}
                        if((lit == "k") || (lit == "K")) {print"$i" >> "k.txt"}
                        if((lit == "l") || (lit == "L")) {print"$i" >> "l.txt"}
                        if((lit == "m") || (lit == "M")) {print"$i" >> "m.txt"}
                        if((lit == "n") || (lit == "N")) {print"$i" >> "n.txt"}
                        if((lit == "o") || (lit == "O")) {print"$i" >> "o.txt"}
                        if((lit == "p") || (lit == "P")) {print"$i" >> "p.txt"}
                        if((lit == "q") || (lit == "Q")) {print"$i" >> "q.txt"}
                        if((lit == "r") || (lit == "R")) {print"$i" >> "r.txt"}
                        if((lit == "s") || (lit == "S")) {print"$i" >> "s.txt"}
                        if((lit == "t") || (lit == "T")) {print"$i" >> "t.txt"}
                        if((lit == "u") || (lit == "U")) {print"$i" >> "u.txt"}
                        if((lit == "v") || (lit == "V")) {print"$i" >> "v.txt"}
                        if((lit == "w") || (lit == "W")) {print"$i" >> "w.txt"}
                        if((lit == "x") || (lit == "X")) {print"$i" >> "x.txt"}
                        if((lit == "y") || (lit == "Y")) {print"$i" >> "y.txt"}
			if((lit == "z") || (lit == "Z")) {print"$i" >> "z.txt"}
                        }
        }
#!/bin/sh

if [ $# -ne 1 ]
	then echo "There are some problems with the parameters! Only one allowed!"
	elif [ ! -f $1 ]
		then echo "$1 does not exist or is not a valid file!"
	else
		mkdir DICTIONAR
		cd DICTIONAR
		echo " " > a.txt
		echo " " > b.txt
		echo " " > c.txt
		echo " " > d.txt
		echo " " > e.txt
		echo " " > f.txt
		echo " " > g.txt
		echo " " > h.txt
		echo " " > i.txt
		echo " " > j.txt
		echo " " > k.txt
		echo " " > l.txt
		echo " " > m.txt
		echo " " > n.txt
		echo " " > o.txt
		echo " " > p.txt
		echo " " > q.txt
		echo " " > r.txt
		echo " " > s.txt
		echo " " > t.txt
		echo " " > u.txt
		echo " " > v.txt
		echo " " > w.txt
		echo " " > x.txt
		echo " " > y.txt
		echo " " > z.txt
		awk -f exe $1 
		sort a.txt
	       	sort b.txt
		sort c.txt
		sort d.txt
		sort e.txt
		sort f.txt
		sort g.txt
		sort h.txt
		sort i.txt
		sort j.txt
		sort k.txt
		sort l.txt
		sort m.txt
		sort n.txt
		sort o.txt
		sort p.txt
		sort q.txt
		sort r.txt
		sort s.txt
		sort t.txt
		sort u.txt
		sort v.txt
		sort w.txt
		sort x.txt
		sort y.txt
		sort z.txt
fi

Hey There,

In the lab5.txt file, your script could just do "touch" to create all files instead of echoing " " into them. That way they won't have blank lines at the top.

Also, the sort calls should be redirected to other files and then copied back over the originals since sort just sends to STDOUT by default.

What kind of errors are you getting?

I'll check the exe.txt next chance I get.

Best wishes,

Mike

oh yes,

It looks like the exe.txt is being called from within the DICTION*** directory, but it's not their initially.

You could copy it down into the directory once you create and then run it, or modify it so that it knows to work on files in the DICTION*** directory instead of the current directory

, Mike

, Mike

Hey There,

If you can work out your scope (where files are when you execute them - the awk file also won't be where you expect it with the way the script is right now), your awk file will work okay, just change the each line that has

{print "$i"  >> "b.txt"}

to

{print $i  >> "b.txt"}

and it will print the words, instead of the literal $i into the files

Hope that helps :)

, Mike

hello eggi,
as far as i remember i tried that kind of print and it printed on the screen...but i'll check it soon again...

Cool,

Just remember to redirect your "sort" output from the shell script to tmp files and then copy back. That's probably what you saw on your screen. The straight-up "sort a.txt" type lines print to the screen and not into your files :)

Cheers,

Mike

:)) the printing was as u said, and the problem was where u mentioned, at sorting..thx very much
;)

This article has been dead for over six months. Start a new discussion instead.