cut or awk command to print first field of first row cut or awk command to print first field of first row bash bash

cut or awk command to print first field of first row


Specify NR if you want to capture output from selected rows:

awk 'NR==1{print $1}' /etc/*release

An alternative (ugly) way of achieving the same would be:

awk '{print $1; exit}'

An efficient way of getting the first string from a specific line, say line 42, in the output would be:

awk 'NR==42{print $1; exit}'


Specify the Line Number using NR built-in variable.

awk 'NR==1{print $1}' /etc/*release


try this:

head -1 /etc/*release | awk '{print $1}'