awk

Add next row to current row using AWK

File.txt : a1 a2 a3 a4 a5 a6 Code : awk '{array[NR]=$0} END {for (i in array) {if (i>1) {{print array[i-1]","array[i]}}}}' File.txt Result : a1,a2 a2,a3 a3,a4 a4,a5 a5,a6 After the all rows are imported to an array, it shows next row to current row under a condition of row > 1.