LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-07-2021, 08:08 PM   #16
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Original Poster
Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660

It's time to declare the winners and mark this thread SOLVED.
These are the solutions with the shortest execution times.

This code ...
Code:
InFile='/usr/share/dict/words'
RW='etaoinshrldu'  # RW = Reference Word
echo "There are "$(wc -l <$InFile)" words in the InFile."

echo
echo '========================================================================='
echo 'Identify letters in each InFile word which are not in the Reference Word.'
echo '========================================================================='

echo; echo 'Method #1 of LQ Member danielbmartin.'
echo 'Reference Word = '$RW
time tr -d "[$RW]" <$InFile |paste -d' ' $InFile - >$OutFileA


echo
echo '========================================================================='
echo 'Now address the mirror-image problem....'
echo 'Identify letters in the Reference Word which are not in each InFile word.'
echo '========================================================================='

echo; echo 'Method #6.2 of LQ Member danielbmartin'
      echo '  using INDEX and MAWK as suggested by shruggy.'
echo 'Reference Word = '$RW
time mawk -v rw=$RW 'BEGIN{n=split(rw,a,"")}
          {NoMatch=""
           for (j=1;j<=n;j++)
             if (!index($0,a[j])) NoMatch=NoMatch a[j]
           print $0,NoMatch}' $InFile >$OutFileG

echo; echo "Normal end of job."; echo; exit
... produced this result ...
Code:
There are 99171 words in the InFile.

=========================================================================
Identify letters in each InFile word which are not in the Reference Word.
=========================================================================

Method #1 of LQ Member danielbmartin.
Reference Word = etaoinshrldu

real	0m0.012s
user	0m0.008s
sys	0m0.004s

=========================================================================
Now address the mirror-image problem....
Identify letters in the Reference Word which are not in each InFile word.
=========================================================================

Method #6.2 of LQ Member danielbmartin
  using INDEX and MAWK as suggested by shruggy.
Reference Word = etaoinshrldu

real	0m0.208s
user	0m0.204s
sys	0m0.000s

Normal end of job.
Daniel B. Martin

.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
regex for phrase like'word-word-word' Zero4 Linux - General 9 07-06-2019 06:36 AM
comparing contents of folders newbiesforever Linux - Software 2 02-01-2009 09:44 PM
Comparing two files to get matched contents in another file using shell script pooppp Linux - Networking 3 08-05-2008 12:11 AM
comparing the contents of entire CDs newbiesforever General 3 08-26-2007 07:03 PM
Comparing files contents? hhegab Linux - Newbie 3 07-01-2004 12:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration