awk print row 1 code example

Example: bash awk how to print specific rows

# Basic syntax:
awk 'row condition goes here {outcome if true goes here}' input_file

# Example usage:
awk 'NR >= 50 && NR <= 100 {print $23, $42}' input_file
# Where
#	- NR is the row number being processed 
#	- This command prints the 23rd and 42nd fields of the input_file for
# 		rows 50-100. 

# More complex example usage:
awk 'BEGIN {OFS="\t"}; {if(NR >= 2 && NR <= 7) print $4; else if (NR == 8) print $0}' input_file
# BEGIN {OFS="\t"}; sets the output field delimiter to tab
# The rest of the statement prints the 4th field of the input_file for
# rows 2-7 and prints all fields for row 8.