Skip to main content
added 147 characters in body
Source Link
swstephe
  • 659
  • 5
  • 11

sed,paste,grep,cut - 109

sed -e 's/[sc]h/6/g;s/[aehiouwxy]//g;y/sztdnmrljkcqgfvpb/00112345677778899/' w|paste w -|grep " $1$"|cut -f1

Takes a file "w", converts each word to its number, paste back to the original, grep for the number and return the word matched. Note that the whitespace after the quote after grep is a tab, paste's default delimiter.

I know Perl is way ahead, just wanted a better shell version as an example.

Oh yeah, the $1 part means that this is supposed to be run from a shell script, (most shells should work), so it takes a command-line argument.

sed,paste,grep,cut - 109

sed -e 's/[sc]h/6/g;s/[aehiouwxy]//g;y/sztdnmrljkcqgfvpb/00112345677778899/' w|paste w -|grep " $1$"|cut -f1

Takes a file "w", converts each word to its number, paste back to the original, grep for the number and return the word matched. Note that the whitespace after the quote after grep is a tab, paste's default delimiter.

I know Perl is way ahead, just wanted a better shell version as an example.

sed,paste,grep,cut - 109

sed -e 's/[sc]h/6/g;s/[aehiouwxy]//g;y/sztdnmrljkcqgfvpb/00112345677778899/' w|paste w -|grep " $1$"|cut -f1

Takes a file "w", converts each word to its number, paste back to the original, grep for the number and return the word matched. Note that the whitespace after the quote after grep is a tab, paste's default delimiter.

I know Perl is way ahead, just wanted a better shell version as an example.

Oh yeah, the $1 part means that this is supposed to be run from a shell script, (most shells should work), so it takes a command-line argument.

Source Link
swstephe
  • 659
  • 5
  • 11

sed,paste,grep,cut - 109

sed -e 's/[sc]h/6/g;s/[aehiouwxy]//g;y/sztdnmrljkcqgfvpb/00112345677778899/' w|paste w -|grep " $1$"|cut -f1

Takes a file "w", converts each word to its number, paste back to the original, grep for the number and return the word matched. Note that the whitespace after the quote after grep is a tab, paste's default delimiter.

I know Perl is way ahead, just wanted a better shell version as an example.