------------------------------------------------------------------------ getline ------------------------------------------------------------------------ getline can be used to read input from the current file or from another file or from a pipe. -------------------------------------- Form What gets set -------------------------------------- getline $0, NF, NR, FNR getline var var, NR, FNR getline < file $0, NF getline var < file var cmd | getline $0, NF cmd | getline var var getline returns 1 ... success 0 ... EOF -1 ... failure (file not found, e.g.) I. Reading from input file Say you want to join two consecutive lines in the input file, "a". $ cat a A B C You may naively try $ awk '{getline x; print $0, x}' a A B C B The reason is that you did not check the status of getline. So you need to check the status of getline first. $ awk '{if(getline x) print $0,x; else print $0;}' a A B C II. Reading from a pipe. Say you want awk to count the number of lines in a file "a" (not the one you are working but some other file).. $ awk 'BEGIN{"wc a" | getline x; split(x,b); print "num lines: "b[2]}' num lines: 3 Of course if you want this program to be robust then you should check for the return status of getline.