Unix/Linux Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

awk command to retrieve record 23 and 89 from UNIX file

Homework & Coursework Questions


Tags
awk, solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 2 Weeks Ago
rakeshp rakeshp is offline
Registered User
 
Join Date: Jul 2016
Last Activity: 16 September 2017, 4:25 PM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
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 nowLinux


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; 2 Weeks Ago at 04:39 PM..
Sponsored Links
    #2  
Old Unix and Linux 2 Weeks Ago
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 22 September 2017, 2:00 AM EDT
Location: Simplicity
Posts: 3,747
Thanks: 306
Thanked 1,257 Times in 1,136 Posts
So it's actually not home work for a course...

Did you read the man pages for awk?

Code:
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.
Sponsored Links
    #3  
Old Unix and Linux 2 Weeks Ago
rakeshp rakeshp is offline
Registered User
 
Join Date: Jul 2016
Last Activity: 16 September 2017, 4:25 PM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
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
    #4  
Old Unix and Linux 2 Weeks Ago
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 22 September 2017, 2:00 AM EDT
Location: Simplicity
Posts: 3,747
Thanks: 306
Thanked 1,257 Times in 1,136 Posts
Yout can do this with two commands

Code:
awk 'NR==23; NR==89'

or with a logical or

Code:
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 (2 Weeks Ago)
Sponsored Links
    #5  
Old Unix and Linux 2 Weeks Ago
rakeshp rakeshp is offline
Registered User
 
Join Date: Jul 2016
Last Activity: 16 September 2017, 4:25 PM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Thank you so much. This is what I am looking for. Thanks alot.
Sponsored Links
    #6  
Old Unix and Linux 2 Weeks Ago
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 22 September 2017, 3:45 AM EDT
Location: San Jose, CA, USA
Posts: 10,503
Thanks: 542
Thanked 3,675 Times in 3,135 Posts
If the input file has a lot more than 89 records, you might also want to try:

Code:
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 (1 Week Ago)
Sponsored Links
    #7  
Old Unix and Linux 1 Week Ago
rakeshp rakeshp is offline
Registered User
 
Join Date: Jul 2016
Last Activity: 16 September 2017, 4:25 PM EDT
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks alot!
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk command to retrieve record 23 and 89 from UNIX file rakeshp UNIX for Beginners Questions & Answers 1 2 Weeks Ago 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
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 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 03:56 AM.