LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-17-2012, 05:12 PM   #1
demet8
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Rep: Reputation: Disabled
using awk to print log in stats to a file


I am using awk to put server login's in a new file. I only need the first 10 login's along fields 1, 5, 6 of a particular user.This is the awk command I am issuing but getting the entire login stats of everyone placed in the new file:

awk '(NR > 1 && NR < 11) {print $1, $5, $6}' last mark > name_date

Last edited by demet8; 10-17-2012 at 05:14 PM.
 
Old 10-18-2012, 12:58 AM   #2
A.Thyssen
Member
 
Registered: May 2006
Location: Brisbane, Australia
Distribution: linux
Posts: 158

Rep: Reputation: 44
Code:
awk '{print $1, $5, $6}  NR == 10  {exit}' input_file > output_file
or if you re-order

Code:
awk 'NR == 11  {exit}  {print $1, $5, $6}' input_file > output_file

NOTE: It is accepted practice for programs to abort when it gets what it needs, and is not a problem when reading from files.

However in some data pipeline or network feeds involving of lots of data, the premature exit can result in the feeder recieving a SIGPIPE, when all the pipe buffers become full. These buffers are however huge on modern computers and it is more likely for the feeding program to finish before the buffer overflows. It depends on the situation. I have seen it so it does happen.

Last edited by A.Thyssen; 10-18-2012 at 01:09 AM.
 
Old 10-19-2012, 01:15 PM   #3
demet8
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thank you A. Thyssen. That helps a lot..
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk: how can I print out a message to the screen when redirecting the output to file. quanba Programming 8 07-13-2015 01:54 AM
[SOLVED] Using AWK to print out the first few lines of a txt file mskalak Linux - Newbie 3 07-27-2011 02:58 PM
Awk+print, create file if not exixt takayama Programming 1 05-15-2011 01:31 PM
[SOLVED] awk print to file question takayama Programming 3 02-05-2011 04:21 PM
awk syntax to print particular record of xyz file? johnpaulodonnell Linux - Newbie 4 06-14-2007 07:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration