Question:
shell script that prints a list of every unique word more than 4 characters in a file in reverse order?
moon
2007-10-29 23:02:49 UTC
shell script that prints a list of every unique word more than 4 characters in a file in reverse order?
Three answers:
morgan
2007-10-31 12:05:59 UTC
There are many ways that these transforms *could*

have been accomplished, but below is a plausible

implementation:



-------------------------------------------------

#!/bin/sh



# Steps in the command pipeline:

# 1) "tr" to convert spaces to newlines in

#     order to put each word on its own line

# 2) "tr" to convert upper case to lower case

# 3) "sed" to remove punctuation and numbers

# 4) "grep" to only match words with at least 4 chars

# 5) "sort" with options:

#    "-r" for reverse lexographic order

#    "-u" to only output unique lines

#

# Note that each line *ends* with a backslash

# (without any trailing spaces) so that these

# physical lines create a single logical line.



tr -s "[:blank:]" "\n" < $1      | \

tr "[A-Z]" "[a-z]"      | \

sed "s/[0123456789,.:;?&-]//g"     | \

grep '[a-z][a-z][a-z][a-z]'      | \

sort -r -u

-------------------------------------------------



I tested this on a copy of the Declaraction of

Independence. That's more text than I want to

put into this answer, but just to see that it

works, here is the the "head" of the output:



  $ words.sh decl_of_independence | head -15

  would

  world

  works

  without

  within

  with

  will

  whose

  wholesome

  while

  which

  whereby

  whenever

  when

  whatsoever
?
2016-10-14 12:25:33 UTC
all I ought to declare is women on UNIX = warm. i'm no longer stable with shell scripts. verify with the Ubuntu help channel in IRC. somebody in there can enable you i'm particular, or you're able to desire to decide for the bash channel in case you needed. extra people in there'll be conscious of what you're attempting to do than on yahoo solutions. i bypass there perpetually for my little unix missions. which distro do you have BTW? =) Edit** its unhappy that i'm so used to answering the "which workstation is ultimate" questions i will't help the only time a genuine question receives asked. i be conscious of slightly approximately UNIX nevertheless so in case you like help i could be satisfied to aim and discern it out with you.
anonymous
2007-10-30 03:03:38 UTC
some combination of sed, uniq and perhaps awk hast to be used. Is this a homework?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...