Find all words containing characters in UNIX

后端 未结 6 935
误落风尘
误落风尘 2021-02-14 15:18

Given a word W, I want to find all words containing the letters in W from /usr/dict/words. For example, \"bat\" should return \"bat\" and \"tab\" (but not \"table\").

He

6条回答
  •  终归单人心
    2021-02-14 15:32

    #!/usr/bin/perl
    $myword=join("", sort split (//, $ARGV[0]));
    shift;
    while (<>) {
        chomp;
        print "$_\n" if (join("", sort split (//)) eq $myword);
    }
    

    Use it like this: bla.pl < /usr/dict/words searchword

提交回复
热议问题