write a shell script that counts a number of unique word
contained in the file and print them in alphabetical order
line by line?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is $1 in shell scripting?

589


What are the default permissions of a file when it is created?

496


What is difference between shell and bash scripting?

541


How to redirect both standard output and standard error to the same location?

627


What does sh mean?

616






What does $1 mean in bash?

614


What are the different types of commonly used shells on a typical linux system?

550


What is awk script?

543


How do you know which shell I am using?

587


Where are cowrie shells found?

574


How would you compare the strings in a shell script?

543


Write the syntax for "if" conditionals in linux?

591


What is echo $shell?

618


What is a scripting language simple definition?

555


Which scripting language is best for automation?

528