Help needed with basic search

hi,

im trying to find the longest word in /usr/share/dict/words that does not contain the letter i.

i've tried using the wc -L command like so: $ wc -L /usr/share/dict/words
which basically tells me the longest word which is good but how do i get the longest word which Does not contain the letter i?

does this have to be displayed in a html table by any chance?

nope. this is just from the shell command

awk '{for(i=0;++i<=NF;){if($i!~"i")a[$i]=length($i)}}END{for(i in a){if(a==max){b=i};if(a>max){max=a;delete b;b=i}};for(i in b){print i}}' file

11PM here , maybe somebody else can cook a better solution :wink:

----------------- Update-----------------------------

This should be a better solution

awk '{for(i=0;++i<=NF;){if($i!~"i"){x=length($i);if(x==max){b[$i]};if(x>max){max=x;delete b;b[$i]}}}}END{for(i in b)print i}' file
1 Like

That looks like my type of solution, long and gets the job done even if theres a shorter way

$ ruby -ne 'BEGIN{a={}};a[$_.chomp!.size]=$_ if $_ !~ /i/; END{p a.sort{|a,b| a[0]<=>b[0]}[-1]}'  /usr/share/dict/words
[25, "regeneratoryregeneratress"]

Perl solution -

$ 
$ 
$ perl -lne '$x=$_ if /^[^i]+$/i && length($_)>length($x);
             END {print $x}' /usr/share/dict/words
regeneratoryregeneratress
$ 
$ 

tyler_durden

1 Like

thanks guys :slight_smile: