Latest LQ Deal: Linux Power User Bundle
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, 03:18 PM   #1
LQ Newbie
Registered: Dec 2017
Posts: 6

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, 03:45 PM   #2
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.4
Posts: 676

Rep: Reputation: 200Reputation: 200Reputation: 200
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, 04:07 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 5,956

Rep: Reputation: 647Reputation: 647Reputation: 647Reputation: 647Reputation: 647Reputation: 647
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 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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:16 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