What is the easiest way to remove 1st and last line from file with awk?

This does the trick:

awk 'NR>2 {print last} {last=$0}'

awk executes the action print last only when NR > 2 (that is, on all lines but the first 2). On all lines, it sets the variable last to the current line. So when awk reads the third line, it prints line 2 (which was stored in last). When it reads the last line (line n) it prints the content of line n-1. The net effect is that lines 2 through n-1 are printed.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)