|
December
8, 2003 -
Pattern
Matching - Substrings - Part II
|
Last
week, pattern matching was used to parse a
variable starting at the beginning (left
side) of the variable. One pound
sign (#) was used to delete the smallest
matching pattern, and two were used to
delete the largest.
If you want to parse a variable
starting at the end (right side) of the
variable, one or two percent signs (%) are
used. Using the same variable from
last week, let's parse the smallest
matching pattern:
|
$
TEXT="livefire_labs_provides_online_unix_training_with_hands_on_lab_exercises"
$ print ${TEXT%_*}
livefire_labs_provides_online_unix_training_with_hands_on_lab
$
|
Notice
that everything to the right of the last
underscore (the smallest matching pattern)
was removed from the variable.
Adding a second percent sign will delete
the largest matching pattern:
|
$ print ${TEXT%%_*}
livefire
$
|
|
|
|
Learn
more...
If you are new to the UNIX or Linux
operating system and would like to learn
more, you may want to consider
registering for LiveFire Labs' UNIX
and Linux Operating System Fundamentals
online training course.
If you already have a solid grasp of the
fundamentals but would like to learn more
about the Korn shell and basic and
advanced shell scripting, taking our Korn
Shell Scripting course will be
beneficial to you.
Our
innovative hands-on training model allows
you to learn
UNIX by completing hands-on
exercises on real servers in our Internet
Lab.
More
Tips...
· Popular
UNIX Tips from the Past
|
|
|
|
|
|
|
Receive
the UNIX Tip, Trick, or Shell Script of the
Week by Email
|
|
|