I am trying to add last line to the file which I am creating. How is it possible to detect the last line of a file in awk before END ? I need to do this because the variables don’t work in the END block,
so I am trying to avoid using END.
awk ' { do some things..; add a new last line into file;}'
before END, I don’t want this:
awk 'END{print "something new" >> "newfile.txt"}'
One option is to use
getlinefunction to process the file. It returns1on sucess,0on end of file and-1on an error.Assuming
infilewith this data:Output will be: