Extract first line from file using awk command

I took an online UNIX course and came across this issue that I am stuck with. Would thank for any help!

You are provided with a set of files, each of which contains personal data about individuals. Each file is laid out in the following format, with one file per person:

 name:Niko Tanaka age:41 occupation:Doctor 

I know the answer should be in the form:

 n=$(awk -F: ' / /{print }' filename) 
+6
source share
2 answers
 n=$(awk -F: '/name/{print $2}' infile) 

Everything inside / / is regular expressions. In this case, you just want to match the string containing the "name".

+4
source
 awk 'NR==1' filename 

Result

 name:Niko Tanaka 
+16
source

Source: https://habr.com/ru/post/907181/


All Articles