awk command to retrieve record 23 and 89 from UNIX file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file? Please let me know what is the awk command for this?

  1. Relevant commands, code, scripts, algorithms:

Awk command in Unix

  1. The attempts at a solution (include all code and scripts):

Looking for only awk command only and not for other commands like sed , head or tail.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

I am looking for a job on where it needs Unix skill.So I am exploring the possible opportunities to gain the skill. I completed my University 2 years ago.I am not studying in any school or university now:b:

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

So it's actually not home work for a course...

Did you read the man pages for awk?

man awk

The record number (usually the line number) is NR. Also because the main code is a loop, you can simply increment an own counter variable.

Hi

yes I studied and know that how to retrieve only one record with the below command awk 'NR==23' emp.lst but with the same command i need to get one more record that is record number 89. Please let me know how to retrieve that also. I am not looking for all the records from 23 to 89. I am just looking for specific records 23 and 89 only

Regards
Rakesh

Yout can do this with two commands

awk 'NR==23; NR==89'

or with a logical or

awk 'NR==23 || NR==89'

This is the short condition{action} form where the default action is print .

1 Like

Thank you so much. This is what I am looking for. Thanks alot.

If the input file has a lot more than 89 records, you might also want to try:

awk 'NR==23;NR==89{print;exit}'

to avoid reading the rest of the file after line/record 89.

1 Like

Thanks alot!