LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-17-2012, 05:21 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 with fields 1, 5, 6 of a particular user.This is the awk command I am issuing but I am 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
 
Old 10-17-2012, 05:49 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
You need to specify the Field Separator as well
Code:
awk -F: '(NR > 1 && NR < 11)  {print $1, $5, $6}' last mark > name_date
 
Old 10-17-2012, 06:09 PM   #3
demet8
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
I am now getting this error on the command line where the last mark command should be reading the last server login's for a subject named mark and then pushing that info to name_date which is a new file created. This is the error message: cmd. line:1: fatal: cannot open file `last' for reading (No such file or directory). When I use last mark @ the beginning of the command it does push out the server login's of mark but it also gives me everyone else's login's info which I don't need.
 
Old 10-17-2012, 06:23 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Just touch the last file.
 
Old 10-17-2012, 09:42 PM   #5
demet8
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thank you very much.
 
  


Reply

Tags
awk


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] using awk to print log in stats to a file demet8 Linux - General 2 10-19-2012 01:15 PM
[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


All times are GMT -5. The time now is 06:35 PM.

Main Menu
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