awk scripts, examples of
Wes Morgan
morgan at ms.uky.edu
Fri Dec 28 02:42:18 AEST 1990
In article <1543 at manta.NOSC.MIL> plantz at 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 at engr.uky.edu |
| Engineering Computing Center | morgan%engr.uky.edu at UKCC.BITNET |
Lint is the compiler's only means of dampening the programmer's ego.
More information about the Comp.unix.questions
mailing list