awk scripts, examples of

awk scripts, examples of

Post by Glen W. Plan » Sun, 23 Dec 1990 05:21:47



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.

I do not use awk, but would like to learn. I have some of the "standard"
references, but would like to see more examples of "working" scripts to
aid in my learning.  Thanks in advance for any help.

==============================================================================
Glen Plantz                             Computer Sciences Corporation
                                        4045 Hancock Street

phone - (619)225-2538

==============================================================================

 
 
 

awk scripts, examples of

Post by Wes Morg » Sat, 29 Dec 1990 00:42:18



Quote:

>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 |


     Lint is the compiler's only means of dampening the programmer's ego.

 
 
 

1. Need semi-non-trivial example of an (MKS) ksh script [really programming-by-example]

We're received a copy of MKS's Unix-like tool kit and it looks pretty
good.

Currently I'm trying to convert a csh script that summarizes the output
of du to a ksh script under MKS's Korn shell.

Can someone help me by forwarding me an example ksh script that
contains a nested if-then-else if-endif sequence and/or a loop?

Thanx.

Michael Herman
Optical Recording Corporation
141 John Street, Toronto, Ontario, Canada  M5V 2E4

UUCP:  { cbosgd!utcs ihnp4!utzoo seismo!mnetor }!syntron!orcisi!michael

2. Traversing character by character

3. expect script help - example script included

4. deadlock in 2.5.62/fs/lockd/svc*.c?

5. AWK documentation + examples needed !

6. how to start program from program

7. AWK examples?

8. Quick date question

9. awk examples/help?

10. QUESTION: AWK examples

11. awk example code

12. QUESTION: awk examples

13. AWK examples?