write a shell script that counts a number of unique word
contained in the file and print them in alphabetical order
line by line?
Answers were Sorted based on User's Feedback
Answer / arup
#!/bin/csh
# Here tr -s ' ' replaces all multiple ' ' with single ' '
# next pipe the above stream to replace each ' ' with '\n'
# next pipe the above stream to get a sorted list of words
# then pipe the unique words to outfile
tr -s ' ' < $1 | tr ' ' '\n' | sort | uniq > $1.out
| Is This Answer Correct ? | 20 Yes | 11 No |
Answer / neennii
sort -u wordtestfile.txt | tee outuniquefile.txt | echo "total unique words are" `wc -w` ; cat outuniquefile.txt
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / trenton g. twining
rm /tmp/$$; \
cat <file> \
| awk '{ for(i=1;i<=NF;i++){ printf("%s\n",$i); }; }' \
| sort -du \
| tee /tmp/$$; \
wc -w /tmp/$$ \
| sed -e "s=/tmp/$$=unique words="
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / manuswami
$ rm -f res res1 ; while read line ; do cat uniqtest | grep
-wc $line >>res1 ; echo "$line :-> Count=" >>res ;done <uni
qtest ; paste res res1 >final_temp ; cat final_temp|sort -u
>final ; rm -f res res1 final_temp1
| Is This Answer Correct ? | 1 Yes | 8 No |
How will you find the 99th line of a file using only tail and head command?
write a program to display all the files from the current directory which are created in particular month
What language is used in terminal?
There are three departments A,B and C.Write a query to display the names of all the persons( in departments other than A) who are paid higher than the person receiving the lowest salary in DEPT A
c program to implement unix/linux command to block the signal ctrl-c and ctrl-\ signal during the execution ls -l|wc -l
How to customise the existing shell?
Explain about non-login shell files?
What is a scripting language simple definition?
Is it possible to substitute "ls" command in the place of "echo" command?
How can any user find out all information about a specific user like his default shell, real-life name, default directory, when and how long he has been using the system?
Suppose you execute a command using exec, what will be the status of your current process in the shell?
What is the use of "$?" Sign in shell script?