The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Retrieving random numbers out of a text file nistleloy UNIX for Dummies Questions & Answers 13 12-14-2008 04:28 PM
retrieving specific lines from a file - can I use grep ? hcclnoodles Shell Programming and Scripting 9 09-23-2008 06:45 AM
Retrieving PID from a file appleforme1415 UNIX for Dummies Questions & Answers 5 10-18-2007 01:44 AM
Automating Rlogin and File Retrieving vicesjr Shell Programming and Scripting 3 04-27-2005 10:30 AM
retrieving a deleted file jyotipg UNIX for Advanced & Expert Users 2 01-04-2002 08:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-12-2009
Mayuri P R Mayuri P R is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 3
Retrieving particular row from a dat file

Hi..

I have a dat file containing both column names and data. Now I want to get only Particular row along with the column names.
My dat fiel is as below

EmpName Dept Salary
Shally Admin 20000
Swati HR 15000
Deepali IT 45000
Preetika EEE 60000

Now I want to display only row 3rd along with column name using awk command.

I tried as below to get the column name ;
awk 'NR==1 {print $0}' Employee.dat
This retrives the column name... now how to get particular row.

  #2 (permalink)  
Old 03-12-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
try something like this
Code:
awk 'NR==1{print}NR==3{print}' filename
  #3 (permalink)  
Old 03-12-2009
Mayuri P R Mayuri P R is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 3
Smile

Thanks alot. Its working fine with the current scenario...

I have one more query. If we know exactly which row to retrieve then this will work fine. Suppose the given dat file contains thousands of records, I just want to retrieve all the rows whose salary is greater tha 15000. How can v acheive that ? In other words can v use expressions(logical,arthmetic, regular...) to retireve the particular rows along with the column name..
  #4 (permalink)  
Old 03-12-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
Use awk...

Code:
$ cat emp.dat

EmpName Dept Salary
Shally Admin 20000
Swati HR 15000
Deepali IT 45000
Preetika EEE 60000
john     ECE  5000

$ awk '{if ($3 > 15000) {print $0}}' emp.dat

EmpName Dept Salary
Shally Admin 20000
Deepali IT 45000
Preetika EEE 60000
  #5 (permalink)  
Old 03-12-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
Quote:
Originally Posted by Mayuri P R View Post
Thanks alot. Its working fine with the current scenario...

I have one more query. If we know exactly which row to retrieve then this will work fine. Suppose the given dat file contains thousands of records, I just want to retrieve all the rows whose salary is greater tha 15000. How can v acheive that ? In other words can v use expressions(logical,arthmetic, regular...) to retireve the particular rows along with the column name..
yes you can
Code:
 
awk 'BEGIN{NR==1{print}$3>15000{print}' filename
  #6 (permalink)  
Old 03-13-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
Quote:
Originally Posted by vidyadhar85 View Post
yes you can
Code:
 
awk 'BEGIN{NR==1{print}$3>15000{print}' filename
Are you sure this will work????
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0