Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!udel!gatech!mcnc!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.unix.wizards Subject: Re: Awk oddity Message-ID: <708@lakart.UUCP> Date: 2 Oct 89 13:46:01 GMT References: <9150@elsie.UUCP> Organization: Lakart Corporation, Newton, MA Lines: 40 ado@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@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+