Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!julius.cs.uiuc.edu!news.cs.indiana.edu!rsg1.er.usgs.gov!ukma!morgan From: morgan@ms.uky.edu (Wes Morgan) Newsgroups: comp.unix.questions Subject: Re: awk scripts, examples of Keywords: awk scripts examples Message-ID: <1990Dec27.154218.3491@ms.uky.edu> Date: 27 Dec 90 15:42:18 GMT References: <1543@manta.NOSC.MIL> Organization: The Puzzle Palace, UKentucky Lines: 55 In article <1543@manta.NOSC.MIL> plantz@manta.NOSC.MIL (Glen W. Plantz) writes: > >I need to use awk to scan a file that consists of lines, each line starting >with an integer, followed by a line of text that should have a period and then >a newline character following that. The script should save the number at the >beginning of the line, and if the line does not have a "period" prior to the >"newline", to print out a message, with the integer number that was at the >beginning of the line. > Well, here's a quick solution to your problem. This has been tested on an AT&T 3B2/1000 running SVR3.2.2....... Given this text file "testtext": 1 this is a test of this function. 2 i think this is an editing application. 3 it might work in any text processor, though 999 a troff-like system could also use this stuff. and this script: #!/bin/sh # # hack out and validate lines preceded by integers. awk '{ linenum = $1; if (index($NF,".") == 0) { printf("Error in line %d; no period\n",linenum); } else { print; } }' testtext You get this output: 1 this is a test of this function. 2 i think this is an editing application. Error in line 3; no period 999 a troff-like system could also use this stuff. If you need some more help, feel free to get in touch. I don't claim that this is an elegant solution, but it's the old "top-of-the-head" solution..... O'Reilly and Associates have just published "sed & awk", the newest of their Nutshell handbooks. It's easy to read, and includes many working scripts, 10 of which were submitted by Usenet readers. -- | Wes Morgan, not speaking for | {any major site}!ukma!ukecc!morgan | | the University of Kentucky's | morgan@engr.uky.edu | | Engineering Computing Center | morgan%engr.uky.edu@UKCC.BITNET | Lint is the compiler's only means of dampening the programmer's ego.