awk question
Andy Behrens
mjm at eleazar.dartmouth.edu
Fri Mar 1 05:11:15 AEST 1991
haozhou at acsu.buffalo.edu (Hao Zhou) writes:
> I am using awk to print some selected lines from a text file. What I
> want to to is to hold off the current line until next line comes in
> and a certain condition is satisfied before printing both lines.
>
> awk '{{if (condition) \
> printf("%s \n %s \n", $prev, $0)}
> {prev=$0}}'
>
>However the variable prev doesn't store the previous line. Instead the
>printf prints out twice the current line. What am I doing wrong?
You should write 'prev' instead of '$prev'. Awk variables (unlike
shell variables) are written without a dollar sign.
The awk statements
n="3"
print $n # or print $(n)
will print the third field of the input line.
--
If you've got a hammer, If the only tool you have
find a nail. is a hammer, you tend to see
(George Bush, January 29, 1991) every problem as a nail.
(Abraham Maslow)
+-------------------+
| Andy Behrens | or: andyb%coat.com at dartmouth.edu
| andyb at coat.com | bitnet: andyb%coat.com at dartcms1
+-------------------+ uucp: {uunet,rutgers}!dartvax!coat.com!andyb
RFD #1, Box 116, East Thetford, Vt. 05043 (802) 649-1258
Burlington Coat, HC 61 Box 1B, Lebanon, N.H. 03766 (603) 448-5000
More information about the Comp.unix.shell
mailing list