LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-07-2018, 03:18 PM   #1
alxreds
LQ Newbie
 
Registered: Dec 2017
Posts: 8

Rep: Reputation: Disabled
Script to change string


Hello
Im try to creat one script to change the values like
D=$(date "+%a %b %d")
Wed Mar 07
And change the output
To "Wed Mar 7"

For generate one report from the "last" command every day

desarrol pts/6 100.101.102.10 Wed Mar 7 12:06 still logged in
desarrol pts/5 100.101.102.10 Wed Mar 7 11:52 still logged in
desarrol pts/4 100.101.102.10 Wed Mar 7 11:23 - 12:29 (01:06)

Any Help me ?

Thanks
 
Old 03-07-2018, 03:45 PM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 1,638

Rep: Reputation: 537Reputation: 537Reputation: 537Reputation: 537Reputation: 537Reputation: 537
You need to use
Code:
D=$(date "+%a %b %e")
so that the day of the month is blank padded instead of 0 padded.
See
Code:
man date
This script should work:
Code:
#!/bin/bash
D=$(date "+%a %b %e")
last | grep "$D"
 
1 members found this post helpful.
Old 03-07-2018, 04:07 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 712Reputation: 712Reputation: 712Reputation: 712Reputation: 712Reputation: 712Reputation: 712
Depending on what informations to retrieve, lastlog is useful too:
Code:
lastlog -b 0 -t 1
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
i am not able to concatenate both the string in shell script as below string spatil20 Linux - Newbie 16 04-24-2016 02:59 AM
[SOLVED] copy string a to string b and change string b with toupper() and count the chars beep3r Programming 3 10-22-2010 07:22 PM
Trying to change String using sed with a string \/home\/user\/Desktop icecoolcorey Programming 10 06-12-2008 11:32 PM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-20-2007 11:14 PM
change case of a string (TOUPPER) in shell script raees Linux - Software 3 05-03-2005 02:13 PM

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

All times are GMT -5. The time now is 08:49 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration