Awk oddity
David Goodenough
dg at lakart.UUCP
Mon Oct 2 23:46:01 AEST 1989
ado at elsie.UUCP (Arthur David Olson) asks:
> A three-part exercise:
>
> 1. Write and test an awk script to print all input lines that contain
> the character 'x'.
> 2. Write and test an awk script to print all input lines that contain
> the character '='.
> 3. Comment on the results.
1.
--- cut here --- cut here --- cut here --- cut here --- cut here ---
#! /bin/sh
awk '{
for (i = 1; i <= length($0); i++)
if (substr($0, i, 1) == "x")
print $0
}'
--- cut here --- cut here --- cut here --- cut here --- cut here ---
2.
--- cut here --- cut here --- cut here --- cut here --- cut here ---
#! /bin/sh
awk '{
for (i = 1; i <= length($0); i++)
if (substr($0, i, 1) == "=")
print $0
}'
--- cut here --- cut here --- cut here --- cut here --- cut here ---
3.
Huh?
Like the man said, "There's no problems, only solutions"
--
dg at lakart.UUCP - David Goodenough +---+
IHS | +-+-+
....... !harvard!xait!lakart!dg +-+-+ |
AKA: dg%lakart.uucp at xait.xerox.com +---+
More information about the Comp.unix.wizards
mailing list