Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-07-2018, 04:18 PM   #1
LQ Newbie
Registered: Dec 2017
Posts: 8

Rep: Reputation: Disabled
Script to change string

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 Wed Mar 7 12:06 still logged in
desarrol pts/5 Wed Mar 7 11:52 still logged in
desarrol pts/4 Wed Mar 7 11:23 - 12:29 (01:06)

Any Help me ?

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

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

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


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 03: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 08:22 PM
Trying to change String using sed with a string \/home\/user\/Desktop icecoolcorey Programming 10 06-13-2008 12:32 AM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-21-2007 12:14 AM
change case of a string (TOUPPER) in shell script raees Linux - Software 3 05-03-2005 03:13 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration