Help needed with basic search


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed with basic search
# 1  
Old 10-01-2010
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?
# 2  
Old 10-01-2010
does this have to be displayed in a html table by any chance?
# 3  
Old 10-01-2010
nope. this is just from the shell command
# 4  
Old 10-01-2010
Code:
awk '{for(i=0;++i<=NF;){if($i!~"i")a[$i]=length($i)}}END{for(i in a){if(a[i]==max){b[i]=i};if(a[i]>max){max=a[i];delete b;b[i]=i}};for(i in b){print i}}' file

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

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

This should be a better solution
Code:
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


Last edited by danmero; 10-02-2010 at 12:27 AM.. Reason: Another solution
This User Gave Thanks to danmero For This Post:
# 5  
Old 10-01-2010
Quote:
Originally Posted by danmero
Code:
awk '{for(i=0;++i<=NF;){if($i!~"i")a[$i]=length($i)}}END{for(i in a){if(a[i]==max){b[i]=i};if(a[i]>max){max=a[i];delete b;b[i]=i}};for(i in b){print i}}' file

11PM here , maybe somebody else can cook a better solution Smilie
That looks like my type of solution, long and gets the job done even if theres a shorter way
# 6  
Old 10-01-2010
Code:
$ 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"]

# 7  
Old 10-02-2010
Quote:
Originally Posted by tryintolearn
... how do i get the longest word which Does not contain the letter i?
Perl solution -

Code:

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

tyler_durden

Last edited by durden_tyler; 10-02-2010 at 12:09 AM..
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help needed - find command for recursive search

Hi All I have a requirement to find the file that are most latest to be modified in each directory. Can somebody help with the command please? E.g of the problem. The directory A is having sub directory which are having subdirectory an so on. I need a command which will find the... (2 Replies)
Discussion started by: sudeep.id
2 Replies

2. Shell Programming and Scripting

Faster search needed

Hope you guys out there can help. I have 2 files as below: file 1: 111,222,333,444,555,666 777,888,999,000,111,222 111,222,333,444,555,888 file 2: 666,AAA 222,BBB 888,CCC I want to get the 6th column from file 1 (example, 666) and check in file 2 for the value in the 2nd column... (9 Replies)
Discussion started by: daytripper1021
9 Replies

3. Shell Programming and Scripting

Search for a pattern and replace. Help needed

I have three variables $a, $b and $c $a = file_abc_123.txt $b = 123 $c = 100 I want to search if $b is present in $a. If it is present, then i want to replace that portion by $c. Here $b = 123 is present in "file_abc_123.txt", so i need the output as "file_abc_100.txt' How can this be... (3 Replies)
Discussion started by: irudayaraj
3 Replies

4. Shell Programming and Scripting

search needed part in text file (awk?)

Hello! I have text file: From aaa@bbb Fri Jun 1 10:04:29 2010 --____OSPHWOJQGRPHNTTXKYGR____ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline My code '234565'. ... (2 Replies)
Discussion started by: candyme
2 Replies

5. Shell Programming and Scripting

Printing 10 lines above and below the search string: help needed

Hi, The below code will search a particular string(say false in this case) and return me 10 lines above and below the search string in a file. " awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print("***********************************");print;c=a;}b{r=$ 0}' b=10 a=10 s="false" " ... (5 Replies)
Discussion started by: vimalm22
5 Replies

6. UNIX for Advanced & Expert Users

search a replace each line- help needed ASAP

can someone help me with the find and replace command. I have a input file which is in the below format: 0011200ALN00000000009EGYPT 000000000000199900000 0011200ALN00000000009EGYPT 000000000000199900000 0011200ALN00000000008EGYPT 000000000000199800000 0011200ALN00000000009EGYPT ... (20 Replies)
Discussion started by: bsandeep_80
20 Replies

7. UNIX for Dummies Questions & Answers

Help needed in search string

Hi , I learning shell scripting.. I need to do the following in my shell script. Search a given logfile for two\more strings. If the the two strings are found. write it to a outputfile if only one of the string is found, write the found string in one output file and other in other... (2 Replies)
Discussion started by: amitrajvarma
2 Replies

8. UNIX for Dummies Questions & Answers

Help needed in Basic UNIX

hi friends, How to obtain list of groups we r a member of and redirect it to a file. how to append the details of current OS to a file. how to append the estimated file space to a file. how to append the details of users loged on along wth their current activity into a file. Thank you...I'm... (3 Replies)
Discussion started by: bobby36
3 Replies
Login or Register to Ask a Question