LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 06: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 06:14 PM.
 
Old 10-18-2012, 01:58 AM   #2
A.Thyssen
Member
 
Registered: May 2006
Location: Brisbane, Australia
Posts: 119

Rep: Reputation: 32
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 02:09 AM.
 
Old 10-19-2012, 02: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Using AWK to print out the first few lines of a txt file mskalak Linux - Newbie 3 07-27-2011 03:58 PM
Awk+print, create file if not exixt takayama Programming 1 05-15-2011 02:31 PM
[SOLVED] awk print to file question takayama Programming 3 02-05-2011 05:21 PM
awk: how can I print out a message to the screen when redirecting the output to file. quanba Programming 5 03-28-2010 06:25 PM
awk syntax to print particular record of xyz file? johnpaulodonnell Linux - Newbie 4 06-14-2007 08:47 AM


All times are GMT -5. The time now is 08:33 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration