LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   using awk to print log in stats to a file (https://www.linuxquestions.org/questions/linux-general-1/using-awk-to-print-log-in-stats-to-a-file-4175432766/)

demet8 10-17-2012 05:12 PM

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

A.Thyssen 10-18-2012 12:58 AM

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.

demet8 10-19-2012 01:15 PM

Thank you A. Thyssen. That helps a lot..


All times are GMT -5. The time now is 03:31 AM.