PIKT

Samples: Find Words in Text

PIKT Logo
Home FAQ News Intro Samples Tutorial Reference Software Authors Licensing SiteSearch


Computer Magazines at Amazon.com

Embedded Systems Programming
Embedded Systems Programming

find_words is a simple Bash script (Linux version) to find words in text.  See the spell_check.pl Perl script for sample use.

#!/bin/bash

# find_words:  find words (strings of one or more characters) in a text stream,
#              and output them, converted to lower case [note: this should be
#              optional], one word per line
#              
#              Usage:  find_words [file]

# for tr, the -c option complements SET1, and -s squeezes repeats

if [ "$#" -eq 0 ]; then
        /usr/bin/tr -cs '[A-Z][a-z]' '[\012*]' | /usr/bin/tr '[A-Z]' '[a-z]'
else
        /usr/bin/tr -cs '[A-Z][a-z]' '[\012*]' < $1 | /usr/bin/tr '[A-Z]' '[a-z]'
fi

[For more examples, see Samples.]

Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software | Authors | Licensing | SiteSearch
Links | SiteIndex | Pikt-Users | Pikt-Workers | Contribute | ContactUs | Top of Page
Page best viewed at 1024x768.   Page last updated 2005-06-22.
This site is PIKT® powered.
PIKT® is a registered trademark of the University of Chicago.
Copyright © 1998-2005 Robert Osterlund.  All rights reserved.

Computer Books at Amazon.com

Minimal Perl: For UNIX and Linux People
Minimal Perl: For UNIX and Linux People

Python in a Nutshell
Python in a Nutshell

Programming Perl
Programming Perl