LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2017, 08:55 PM   #1
souchai
LQ Newbie
 
Registered: Jan 2017
Posts: 3

Rep: Reputation: Disabled
writing command line and create a awk file


how do I write a the command line “last –wi > mylogin” to create a file called mylogin that shows all login information on sp-cfsics.um.com since “Jan 24,” and then write an awk script, myawk, to determine how many lines in mylogin contain the string “cis264fs1702”.
 
Old 03-14-2017, 01:31 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by souchai View Post
how do I write a the command line “last –wi > mylogin” to create a file called mylogin that shows all login information on sp-cfsics.um.com since “Jan 24,” and then write an awk script, myawk, to determine how many lines in mylogin contain the string “cis264fs1702”.
How far back does wtmp go? You may have to query some of the older files, too. Using last with the -F option will give you the full date and time of each login.

Once you've figured out how to use last to get what you need, I'd recommend using a pipe | to send the data to awk instead of using temporary files. If your assignment requires using temporary files, then tempfile is the safe and reliable way to chose a name.

How far have you gotten with awk and where are you stuck? You need to use the END { } stanza to print your sum. See these two resources:

https://www.ibm.com/developerworks/library/l-awk1/
http://www.grymoire.com/Unix/Awk.html#uh-1
 
Old 03-14-2017, 01:28 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
souchai, welcome to LQ.

You seem to be writing a few threads related to direct questions about "how to" for awk scripting. As has been pointed out in one other thread, you should show your work and indicate where you are stuck. LQ members are volunteers and not here to provide on demand code for your projects.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 12:46 AM
command line, create iso file and burn it on a CD zeelog Debian 3 05-14-2013 07:10 PM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 10:49 AM
AWK/BASH: get nth line from a file by getline feed to actions in a same awk line cristalp Programming 3 11-23-2011 11:38 AM
how do i create an empty bash(.sh) file in command line? bbmak Linux - Newbie 1 10-26-2007 02:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:32 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
Open Source Consulting | Domain Registration