awk question
    Art Neilson 
    art at pilikia.pegasus.com
       
    Thu Feb 28 20:56:20 AEST 1991
    
    
  
In article <62322 at eerie.acsu.Buffalo.EDU> 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. So I
>need to store the current line in some variable as follows:
>
>	prev = 'initialization'
>	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?
>
>Thanks for any help on this problem.
>
>
>	Hao
>	
>-- 
>Internet:haozhou at acsu.buffalo.edu BITNET:haozhou%acsu.buffalo.edu at UBVM.BITNET
>UUCP: rutgers!ub!haozhou
All your curly braces are quite confusing.
This looks like what you're trying to do.
awk '
BEGIN {
	prev = 'initialization'
}
{
	if (condition)
		printf("%s \n %s \n", prev, $0)
	prev = $0
}'
-- 
Arthur W. Neilson III		| INET: art at pilikia.pegasus.com
Bank of Hawaii Tech Support	| UUCP: uunet!ucsd!nosc!pegasus!pilikia!art
    
    
More information about the Comp.unix.shell
mailing list