I have searched, but have come up short with an answer. I want to print the last line (or record) in a file; then print the first line using only awk. I know how to print first line:NR == 1{print}and last lineEND{print}However, how can I switch the positions? Is it even possible? I only get errors when I try to do so. Is there a way to integrate the NR == 1{print}command into the END command? Again, I only want to perform this in awk. Thanks!
Is there a way to print last line of a file then first line of a file in awk only?
awk
Just save the first line to a variableawk 'NR==1 {first = $0} END {print; print first}' fileEx. given file asline 1line 2line 3line 4line 5then$ awk 'NR==1 {first = $0} END {print; print first}' fileline 5line 1