filename: awktail.txt author: Eric Pement date: 2002 Oct 13 Beware about making unsafe assumptions about the "tail" or end of a line. I used to need to refer to the end of a line from the 3rd field to the end, and I have used a variable like this: tail = substr($0,index($0,$3)) Note that I was attempting create a tail variable which begins at $3 and goes to the EOL. However, in a line like this: aa aabbcc bb dd ee that technique will assign "bbcc bb dd ee" to the 'tail' variable, and not "bb dd ee", as I often expected. Here are some potential solutions to the 'tail problem': SOLUTION 1: # Works if you don't mind deleting $1 and $2, and if you know # the space delimiters between them: $1 = "" $2 = "" tail = substr($0, 3) # remove superfluous delimiter after $1, $2 SOLUTION 2: # Does not require deleting $1 and $2 # Still assumes there is only 1 space between words. # Get the tail, starting at field $3 tail = substr($0,length($1 $2) + 3) # One more example: Get the tail, starting at field $4 tail = substr($0,length($1 $2 $3) +4) SOLUTION 3: # Works if there are variable spaces between words # get tail beginning at $4 tail=$0; for (i=1;i<4;i++) sub($i,"",tail); sub(/ */,"",tail) #---end of file---