Home Man
Today's Posts

Students must use and complete the template provided. If you do not use the template your post may be deleted! Special homework rules apply here.

awk command to retrieve record 23 and 89 from UNIX file

awk, solved

👤 Login to reply

Thread Tools Search this Thread
# 1  
Old 09-01-2017
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?

2. Relevant commands, code, scripts, algorithms:

Awk command in Unix

3. 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.

4. 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

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).

Last edited by rakeshp; 09-01-2017 at 04:39 PM..
# 2  
Old 09-02-2017
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.
# 3  
Old 09-04-2017

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

# 4  
Old 09-04-2017
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.
The Following User Says Thank You to MadeInGermany For This Useful Post:
rakeshp (09-04-2017)
# 5  
Old 09-04-2017
Thank you so much. This is what I am looking for. Thanks alot.
# 6  
Old 09-05-2017
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.
The Following User Says Thank You to Don Cragun For This Useful Post:
rakeshp (09-09-2017)
# 7  
Old 09-09-2017
Thanks alot!
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to search a text in file and retrieve required lines following it with UNIX command? Arunkumarsak4 UNIX for Beginners Questions & Answers 8 01-25-2018 09:06 AM
awk command to retrieve record 23 and 89 from UNIX file rakeshp UNIX for Beginners Questions & Answers 1 09-01-2017 03:02 PM
Help with Getting distinct record count from a .dat file using UNIX command MS06 Shell Programming and Scripting 1 06-07-2016 01:35 AM
awk command to omit trailer record in a file abhilashnair Shell Programming and Scripting 4 07-14-2014 07:06 AM
[Solved] awk command to read sequentially from a file until last record jaldo0805 Shell Programming and Scripting 4 06-04-2013 02:15 PM
Retrieve the record using 2,2 lines and display the ouput in columnwise chakkaravarthy Shell Programming and Scripting 10 06-23-2011 08:11 AM
How to retrieve data using awk command prasad4004 Shell Programming and Scripting 5 07-30-2010 04:08 AM
grep command to retrieve one file toejam Shell Programming and Scripting 9 05-02-2009 11:21 PM
how to read record by record from a file in unix raoscb UNIX for Dummies Questions & Answers 1 05-16-2008 06:30 AM
how do we retrieve a line from a file in unix lmadhuri Shell Programming and Scripting 2 02-07-2007 07:07 AM

All times are GMT -4. The time now is 06:03 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password