: >Can anybody tell me how to do what Perl does by
: >
: >open FL, "myfile.txt" #I can do exec 3< myfile.txt in ksh
: >while (<FL>) #I can do read -u3 line_buf
: >{ if (/MyPattern/) {... #How can I match part of a string?
: >
: >Or, how can make a pattern match in ksh on a given string (match part of the
: >matches the pattern once. But match on what string? In Perl, you can say
: >$line_buf =~ /MyPattern/ to force the match on $line_buf. There's no
: >equivalent of =~ in Korn shell, is there?
: >
: >Thanks for your help.
: >
: >Yong
: Grep, sed, awk (choose one)
Only if regular expression matching is required, in which case
expr should be mentioned. However, the Korn shell has a very
powerful set of pattern matching expressions that should not be
overlooked.
while read line
do
if [[ "$line" = pattern ]]; then
action
else
action
fi
done < file
For instance
while read line
do
if [[ "$line" = *Kansas* ]]; then
# do something for entries containing the word "Kansas"
This can also be expressed negatively
if [[ "$line" = !(*Kansas*|*Missouri*|*Arkansas*|*Iowa*) ]]; then
Read up on "File Name Generation" in the manpage for more info.
In many cases, you can do things with File Name Generation that
wouldn't be achievable with regular expressions.
: Chuck Demas
: Needham, Mass.
: --
: Eat Healthy | _ _ | Nothing would be done at all,
: Die Anyway | v | That no one could find fault with it.
--
Dan Mercer
Opinions expressed herein are my own and may not represent those of my employer.