(OLD) (ARCHIVED) Puppy Linux Discussion Forum Forum Index (OLD) (ARCHIVED) Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info

This forum can also be accessed as http://oldforum.puppylinux.com
It is now read-only and serves only as archives.

Please register over the NEW forum
https://forum.puppylinux.com
and continue your work there. Thank you.

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups    
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 26 Feb 2021, 23:14
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
"This Week" script: in bash, awk, or whatever.
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. View previous topic :: View next topic
Page 4 of 7 [97 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7 Next
Author Message
puppy_apprentice


Joined: 07 Feb 2012
Posts: 300

PostPosted: Wed 21 Nov 2018, 19:11    Post subject:  

musher0 this code you can use in your scripts:

Code:
#!/bin/sh
colors=$(echo -e "34\n35\n36\n37"); colmatrix=($colors); r=$((RANDOM%4)); echo -e "\e[${colmatrix[$r]}m Hello World! \e[0m"
Screenshot_2018-11-22_000937.jpg
 Description   Immortal "Hello Worlds!" in 4 ANSI colors
 Filesize   46.9 KB
 Viewed   264 Time(s)

Screenshot_2018-11-22_000937.jpg

Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Wed 21 Nov 2018, 19:59    Post subject:  

@puppy_apprentice:

Your modesty is quite to be commended. But judging by your recent output,
I'd say that you're well on your way of surpassing at least this supposed
"Bash magic" master... (I.e. me.)

That's fine, and please go for it! I have serious reservations about the
traditional concept of "competition", but I'm all for "emulation".

My best wishes to you in this! Very Happy

BFN.

_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
puppy_apprentice


Joined: 07 Feb 2012
Posts: 300

PostPosted: Wed 21 Nov 2018, 20:11    Post subject:  

I was thinking about your ThisWeek.sh script in wich you use ANSI codes.

Ok. I have some experience with other programming languages but i'm not fluent in any.

I think that for example i won't write this kind of sed game:

https://aurelio.net/projects/sedsokoban/

Have a nice day/evening all.
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Wed 21 Nov 2018, 21:05    Post subject:  

Thanks for the feedback, puppy_apprentice.

~~~~~~~~~~~
@all:

If anyone is interested, I have made available the latest version of
coreutils, version 8-30, for PuppyLinux, here.

To anyone wondering: the link with this thread is that the GNU coreutilis
contain, among many others, three utilities used in various scripts in this
thread: cal (the full version), date and nl.

BFN.

_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Thu 22 Nov 2018, 04:18    Post subject:  

Hello all.

In lieu of < nl > to number lines, one can use < cat -n >:
Code:
>echo;cal | grep -v [[:alpha:]] | cat -n | grep --color=always "$(date '+%d')"

Also possible for this is the use of < grep -n >, as mentioned somewhere
above by puppy_apprentice IIRC:
Code:
echo;cal | grep -v [[:alpha:]] | grep -n --color=always "$(date '+%d')" | tr ":" "\t";echo -e "\e[1A\e[1Cth wk:"
This is completed by a replacement, through < tr >, of the colon by a tab,
and then we insert for information the string "th wk:" between the week
number and the line of dates, through a couple of ANSI escape codes.

We can decorate it like so:
Code:
echo;echo -e "\t      \e[33m\e[4m`date '+%b %Y'`\e[0m";cal | grep -v [[:alpha:]] | grep -n --color=always "$(date '+%d')" | tr ":" "\t";echo -e "\e[1A\e[1Cth wk:";echo -e "\t\e[33m`cal | grep -v [[:digit:]]`\e[0m"
Scrot attached.

BFN.
ThisWeek-example4.jpg
 Description   
 Filesize   23.91 KB
 Viewed   232 Time(s)

ThisWeek-example4.jpg


_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4481
Location: holland

PostPosted: Thu 22 Nov 2018, 05:16    Post subject:  

musher0 wrote:
If anyone is interested, I have made available the latest version of
coreutils, version 8-30, for PuppyLinux, here.

To anyone wondering: the link with this thread is that the GNU coreutilis
contain, among many others, three utilities used in various scripts in this
thread: cal (the full version), date and nl.


Hi musher0, I couldn't find 'cal' in your pet.
On my Debian stretch system none of codes here work unless I change 'cal' to 'busybox cal' (not a problem, btw, just curious about 'cal (the full version)'.
(on my system /usr/bin/cal is symlink to /usr/bin/ncal part of package bsdmainutils)

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Thu 22 Nov 2018, 08:48    Post subject:  

fredx181 wrote:
musher0 wrote:
If anyone is interested, I have made available the latest version of
coreutils, version 8-30, for PuppyLinux, here.

To anyone wondering: the link with this thread is that the GNU coreutilis
contain, among many others, three utilities used in various scripts in this
thread: cal (the full version), date and nl.


Hi musher0, I couldn't find 'cal' in your pet.
On my Debian stretch system none of codes here work unless I change 'cal' to 'busybox cal' (not a problem, btw, just curious about 'cal (the full version)'.
(on my system /usr/bin/cal is symlink to /usr/bin/ncal part of package bsdmainutils)

Fred
By golly, you're right, Fred.
I mistook cat for cal...
Sorry about that. (Note to myself : must get new glasses...)

Back hunting. TWYL.

~~~~~~~~~~~
Edit, 5 minutes later --
cal is part if the utils-linux package, whose latest source is here.

Edit, an hour later --
I have compiled the latest utils-linux package, version 2.33, for
PuppyLinux. It is available through here.

Again thanks to Fredx181 for having a falcon's eye.

BFN.

_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 2084
Location: Japan

PostPosted: Thu 22 Nov 2018, 10:47    Post subject:  

musher0 wrote:
Also possible for this is the use of < grep -n >, as mentioned somewhere
above by puppy_apprentice IIRC:
Code:
echo;cal | grep -v [[:alpha:]] | grep -n --color=always "$(date '+%d')" | tr ":" "\t";echo -e "\e[1A\e[1Cth wk:"

There is more to learn from puppy_apprentice's code:
Reread how he fixed the date command to prepare for single digit dates and how he uses the -w option for the grep command, a clever trick. On the first day of the month grep will match only '1' but not '10' or '21'
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Thu 22 Nov 2018, 14:05    Post subject:  

Hi, MM.

I'm sure. But not now, please.

Back later.

_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4481
Location: holland

PostPosted: Thu 22 Nov 2018, 15:27    Post subject:  

musher0 wrote:
I have compiled the latest utils-linux package, version 2.33, for
PuppyLinux. It is available through here.


Thanks, the cal included works fine for me.

P.S. see screenshot , running just cal, note that 'busybox cal' is not translated, cal from utils-linux and ncal are in Dutch, as my system locale is set (and ncal looks very different)
(and translated, the week goes from monday to sunday)

Fred
2018-11-22-201728_839x563_scrot_639x429.png
 Description   Different cal's
 Filesize   79.24 KB
 Viewed   147 Time(s)

2018-11-22-201728_839x563_scrot_639x429.png


_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Thu 22 Nov 2018, 15:34    Post subject:  

@fredx181:
With the "real" < cal >, you have to say < cal -s > for the week to start
on Sunday.

_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Thu 22 Nov 2018, 16:39    Post subject:  

@MochiMoppei and puppy_apprentice:
I studied it, but I really do not understand the random color part in
puppy_apprentice's script. Worse: I do not understand the need for it! Sad

In particular, the part X1X2, etc. and the line of dates. How do you get
that XIX2, etc. part to appear? In an hex editor? I could not reproduce
it by any means I know.

Sorry.

~~~~~~~~~~
I did catch the need for < grep -wn $(date '+%d'>, however; not just
< grep -n >.

And MM, any reason why your syntax is different than mine for
< date '+%d' >? They give the same result.

BFN.

_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4481
Location: holland

PostPosted: Thu 22 Nov 2018, 17:13    Post subject:  

musher0 wrote:
@fredx181:
With the "real" < cal >, you have to say < cal -s > for the week to start
on Sunday.


Ah, ok, btw for me with LANG=en_US the week starts automatically on Sunday without the -s switch :
Code:
root@live:~# LANG=en_US cal  # full cal
    November 2018   
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 

So somehow it seems to detect which locale.

Fred

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 15041
Location: Gatineau (Qc), Canada

PostPosted: Thu 22 Nov 2018, 18:00    Post subject:  

Hi Fred.

Thanks for the feedback.

The authors must've improved it. In older versions that I've used, the -s
was needed if you wanted the week to start on Sunday.

As well, you may have noticed that the real cal highlights today's date,
whereas the busybox cal does not.

BFN.

_________________
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 2084
Location: Japan

PostPosted: Thu 22 Nov 2018, 19:32    Post subject:  

musher0 wrote:
And MM, any reason why your syntax is different than mine for
< date '+%d' >? They give the same result.
Exactly which syntax are you referring to?
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 4 of 7 [97 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7 Next
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0577s ][ Queries: 12 (0.0094s) ][ GZIP on ]