"This Week" script: in bash, awk, or whatever.

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#81 Post by puppy_apprentice »

musher0 wrote:What do you think?
When i'm changing dates in your script i have wrong solutions. Or maybe i'm doing something wrong?

I made another versions. Not short like Mochi's (Hail to the Caesar ;)):

1.

Code: Select all

#!/bin/sh
#shorter version of my earlier script
day=$1
month=$2
year=$3

# array with names of days
nod=($(cal $month $year | head -2 | tail -1))

# number of days in week that include $day
cdiw=$(cal $month $year | grep -w $day | wc -w)

# number of days in week before $day
dbd=$(($(cal $month $year | grep -w "$day" | tr ' ' '\n' | grep -wB 7 "$day" | wc -w)-1))

if (( $cdiw < 7 )) && (( $day < 7 ));
then
	echo "$day/$month/$year is ${nod[7-$cdiw + $dbd]}"
else
	echo "$day/$month/$year is ${nod[dbd]}"
fi
2.

Code: Select all

#!/bin/sh
# idea of use pr command
day=$1
month=$2
year=$3

# vertical list of week names
n=$(cal $month $year | head -2 | tail -1 | tr ' ' '\n')

# store whole week which include $day
k=$(cal $month $year | tail -n +3 | grep -w $day)

# Mochi's stuff, strip 3 spaces and 2 spaces to 1 space
k=${k//   /  }
k=${k//  / }

# vertical list of week which include $day
k=$(echo "$k" | tr ' ' '\n')

#vertical lists $n and $k together
dow=$(echo -e "$n\n$k" | pr -t -s" " --column 2 | grep -w $day)

echo "$dow/$month/$year"

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#82 Post by MochiMoppel »

I also made a new version. Shorter, faster and simpler. The ugly loop is gone.
After all a stupid and completely useless script should at least look good :wink:

Code: Select all

#!/bin/bash
day=3
month=6 
year=2011

CAL=$(cal $month $year) 
CAL=${CAL#*$'\n'} 
CAL=${CAL//   / x } 
CAL=(${CAL%%$day*})
CNT=${#CAL[@]}
echo "$day/$month/$year is ${CAL[$((CNT%7))]}"

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#83 Post by musher0 »

Ahem.

I did say "completely useless" in the sub-title, but I did not say "stupid".
Your take on it, MM! :D

Besides, is there was a way one could click on the date, and maybe a diary
or schedule opened? Then it would stop being useless.

Is there? I mean: is there a way one can click on a character in a
CLI program, and some other CLI program or script pops up?

And a fading echo repeated: "CLI program, CLI progr...". :lol:

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#84 Post by puppy_apprentice »

MochiMoppel wrote:After all a stupid and completely useless script should at least look good :wink:
Nothing is stupid if you can learn from it. I've learned some tricks from you. Without those 'stupid' scripts i would have to search those stuff in manuals. Now i have got working examples. ;)

Working nice in MobaXTerm in Windows (attached picture).
https://mobaxterm.mobatek.net/
Attachments
Bash_in_Windows.jpg
Mochi's script in action!
(91.17 KiB) Downloaded 312 times

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#85 Post by musher0 »

More uselessness! :lol:

Code: Select all

#!/bin/bash
# /root/my-applications/bin/mois_zeros+espaces.sh
# Sketch by musher0 26 Nov. 2018. GPL3.
# Requires awk, replaceit, tr, and paste.
# (Not tomato paste, silly!!! The utility!).
####
# Syntax should be mois_zeros_espaces.sh month year, but there
# is a safeguard: it defaults to current month and year if the
# script finds no positional parameters.
[ "$1" ] && A=$1 || A="`date '+%m'`" # mois
[ "$2" ] && B=$2 || B="`date '+%Y'`" # année

EnTete="`cal $A $B | grep -vE [[:digit:]]`" 
echo " " > mois.txt # For better appearance in the end.
cal $A $B | grep -vE [[:alpha:]] | tr " " ";" >> mois.txt
num="";for num in {1..9};do 
	replaceit --input=mois.txt ";;$num" ";0$num" 
done 
num="";for num in {1..9};do 
	replaceit --input=mois.txt ";$num;" "0$num;" 
done  
i=1
for i in {1..7};do 
	replaceit --input=mois.txt ";;;" "oo "
	i="$[$i+i]"
done
# Maintenant on a un mois avec des dates de même longueur,
# tous séparés par un espace. /
# Now we have a month with dates of same length, all
# separated by a space.

echo $EnTete >> mois.txt
cat mois.txt | tr ";" " "  > mois.txt2

for i in {1..7}; do 
	awk '{ print $'$i' }' mois.txt2 | tr "o" "-" > jours$i.txt
done
echo; echo -e "\t\t`cal $A $B | head -1`"
paste jours*.txt
Scrot attached.

Ok. Not exactly on thread. But I found this experiment interesting,
because it enables to treat a month as a DB, in columns, by day of week.
With the default cal, one cannot, because the single-digits days are not
zero-padded.

Once we have the columns (in files jours1.txt, jours2.txt, etc.), we can do
what we want with them, even recreate a pseudo-cal with the paste utility!
(See scrot.)

Or you can type < more jours5.txt >, say, to view all dates for the
Thursdays of the month, etc.

I thought I'd share this with you.

BFN.
Attachments
More-Uselessness.jpg
A little time machine!!!
(145.67 KiB) Downloaded 297 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#86 Post by musher0 »


Attachments
dateutils.tree.zip
(524 Bytes) Downloaded 93 times
dateutils-4.6.pet
(219.13 KiB) Downloaded 123 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#87 Post by MochiMoppel »

puppy_apprentice wrote:Nothing is stupid if you can learn from it.
So true :lol:
One thing I learned is that it can be useful when cal displays multiple color marked days and not just a single day.
With little extra code it is possible to pull dates from a database and mark them in the calendar. These dates can be public holidays, birthdays, dentist appointments or whatever.

What I also learned is that grep is pleasantly easy to use but that it is inflexible when it comes to determining the mark color. It's red.
There are ways to change this globally, but why bother? Using sed gives not only full control over the color, it also allows alternative markings, not just ANSI C escape codes. This will become important when writing cal output to GUI dialogs like yad or gtkdialog. These dialogs would know nothing about ANSI C, they would require Pango markup.

The following demo is portable (see shebang) and works for $day being a single day or multiple days. For latter case a regex pattern is required. Separating days with '|' is probably the easiest way to define a range of days.

Code: Select all

#!/bin/busybox ash
day='6|24|25' 
month=12 
year=2018
cal $month $year | grep -EwC8 --color=always "$day"

BLD=1  #bold: 0=off 1=on
FGD=37 #foreground: 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white 
BGD=45 #background: 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white 
cal $month $year | sed -r "s/\b($day)\b/\x1B[$BLD;$FGD;${BGD}m\1\x1B[0m/g"
Attachments
multiple_days.png
(4.97 KiB) Downloaded 225 times

Burunduk
Posts: 80
Joined: Sun 21 Aug 2011, 21:44

#88 Post by Burunduk »

MochiMoppel wrote:The following demo is portable (see shebang) and works for $day being a single day or multiple days.
Very good! But doesn't work with busybox grep and sed.


grep --color --> unrecognized option '--color=always'

\x1b --> same as the literal string "x1b"

\b --> works on the PC, not on the phone. Probably because of the bionic C library.



This is the modification that works on my phone too:

Code: Select all

#!/bin/busybox sh

days=" 5|25|26|30|31"
on=$'\x1b'"[1;37;42m"
off=$'\x1b'"[0m"

cal "$@" | sed -r 's/('"$days"')( |$)/'"$on\1$off"'\2/g'


And this is an attempt to combine the two exercises:

Code: Select all

#!/bin/busybox sh

BB=busybox

days=" 5|25|26|30|31"
on=$'\x1b'"[1;37;42m"
off=$'\x1b'"[0m"


$BB cal "$@" | $BB sed -nr '
    1 p; 2 s/(..).(.{17})/\2 \1/p
    3 { s/.*/                  &/; s/ {21}// }
    3,$ { $!N; s/\n/ /g; s/.{21}/&\n/
          h; s/\n.*//; s/('"$days"')( |$)/'"$on\1$off"'\2/g; p; g; D  
        }
'

BTW busybox paste supports custom delimiters but not the empty one. I've invented a square wheel to test your script. It's awkward but doesn't require temporary files.

Code: Select all

BODY=$(busybox awk -v col1="$REST" -v col2="$SUND" 'BEGIN { n = split(col1,a1,"\n"); split(col2,a2,"\n"); for (i = 1; i <= n; i++) print a1[i] a2[i] }')

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#89 Post by musher0 »

Hello Burunduk.

I just did a < busybox --list > on my xenialPup, and it does not have a
< busybox awk >. Version is BusyBox v1.24.2 (2016-05-06). The xenialPup
has gawk by default, though.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#90 Post by MochiMoppel »

Burunduk wrote:Very good! But doesn't work with busybox grep and sed.
It wasn't meant to be *that* portable :lol:
But of course I like the idea to make it busybox only.
This is the modification that works on my phone too:
Are you sure? Does not work when the year is 2018 and day is the 18th :wink:

Here is my take:

Code: Select all

#!/bin/busybox ash
days=" 1| 2|1[0-9]" 
on=$'\x1b[1;37;42m' 
off=$'\x1b[0m' 
busybox cal  8 2018 | busybox sed -r "s/(^| )($days)( |$)/\1$on\2$off\3/g; s/(^| )($days)( |$)/\1$on\2$off\3/g"
May look odd. Unlike the GNU version busybox sed would not match consecutive dates and skips every 2nd match. Works when sed repeats the substitution process. Don't know how to fix this more elegantly.
[Edit]Found it. Basically your version. Just excludes 1st line from pattern matching:

Code: Select all

busybox sed -r "1!s/($days)( |$)/$on\1$off\2/g"
And this is an attempt to combine the two exercises:
First I need a strong coffee for that ....
BTW busybox paste supports custom delimiters but not the empty one. I've invented a square wheel to test your script. It's awkward but doesn't require temporary files.
Wrong thread. Please post to cal command alternatives
BTW Neither busybox awk nor busybox paste exist in my Slacko version.
Attachments
portable_cal.png
(2.31 KiB) Downloaded 134 times
Last edited by MochiMoppel on Wed 05 Dec 2018, 12:55, edited 1 time in total.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#91 Post by musher0 »

Sorry to bother you!

I'm sure this insignificant script displaying a month

-- colored with some colors in the 90's register of ANSI codes
-- fading according to in-focus and out-of-focus
-- with the single numbers of the month padded
-- with a little motto at the bottom (hopefully inspiring!)
-- using < rxvt > and < less > to produce a pseudo-GUI
-- multilingual (plus you could add your own locale)
-- with a suggested entry for a pekwm or ae menu

is off-topic and of no interest to anyone! ;)

BFN
Attachments
hic-et-nunc4-EN.jpg
(62.99 KiB) Downloaded 352 times
hic-et-nunc4.sh.zip
(2.25 KiB) Downloaded 100 times
hic-et-nunc4.jpg
French version (sorry to impose).
But if LANG variable NOT set to fr, will display in English.
(65.43 KiB) Downloaded 422 times
Last edited by musher0 on Thu 06 Dec 2018, 23:05, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#92 Post by puppy_apprentice »

MochiMoppel wrote: With little extra code it is possible to pull dates from a database and mark them in the calendar. These dates can be public holidays, birthdays, dentist appointments or whatever.
I'm working on something similar with coloring done it this way (without curses it will be hard to make windows and menus but i'm thinking to use 'select' or 'tput' command):

Code: Select all

cal | grep -w --color=always "$(seq 1 2 31)" | sed 's/31m/32m/g'
or

Code: Select all

a=$(cal | grep -w --color=always "$(seq 1 2 31)"); echo "${a//31m/34m}"

Code: Select all

cal | grep -w -B 6 -A 6 --color=always 10 | sed 's/31m/32m/g' | grep -w -B 6 -A 6 --color=always 20
where '31' is standard color from grep command.

Burunduk
Posts: 80
Joined: Sun 21 Aug 2011, 21:44

#93 Post by Burunduk »

MochiMoppel wrote:Are you sure? Does not work when the year is 2018 and day is the 18th :wink:
Thank you for fixing that nasty bug :)

I like your idea of using "pipe-separated values" as a part of a regexp. It is also possible to apply this technique to the entire year view:

Code: Select all

#!/bin/bash

# Highlights dates from two sets in the cal command output
# using distinct styles (in the month and year view).
# Requires GNU sed. Busybox sed doesn't understand multibytes chars
# (it seems to be the compile option).
# It also doesn't support s/.../.../Ng options combo
# but this can be worked around:
#
# mark_days="$mark_days
#     $addr,+6 { s/./!/22; s/./!/44; s/...?!?/%$i-&/g
#                :a$i; s/(!.*%)$i/\1$((i+1))/; ta$i; s/!/ /
#                :b$i; s/(!.*%)$((i+1))/\1$((i+2))/; tb$i; s/!/ /
#              }"
#
# Usage: ./this_script [ [month] year ]
# No error checking. This is just a demo. 

# cal and busybox cal insert empty lines in different places
CALCMD="busybox cal" addr=4 inc=8
#CALCMD="cal -h" addr=3 inc=9

# Highlight:
# 1st set of days
daysA="1-1|1-7|12-25|12-26|12-31"
# 2nd set of days
daysB="1-2|12-31"
# columns
daysC="1|6|7"

# Styles:
onA=$'\x1b[1;37;42m'    # for the 1st set
offA=$'\x1b[0m'         # turn the style off

onB=$'\x1b[1;35m'       # for the 2nd set
offB="$offA"

onAB=$'\x1b[1;37;45m'   # for the intersection of the two sets
offAB="$offA"

onC=$'\x1b[1;31m'       # for columns (if no other style applies)
offC="$offA"


# Settings for the month and year view
case $# in
    0)  months=`date +%m`
        addr=2
        ;;
    1)  months='1 4 7 10'
        ;;
    2)  months=${1%%[^0-9]*}
        addr=2
        ;;
esac

# Generate repetitive parts of the sed script:

# add month labels before every 3rd char (skipping spaces between months)
mark_days=
for i in $months; do
    mark_days="$mark_days
        $addr,+6 { s/./!/22; s/./!/44; s/...?!?/%$i-&/g; s/!/ /g
                 s/%$i/%$((i+1))/8g; s/%$((i+1))/%$((i+2))/8g
                 } "
    addr=$((addr+inc))
done

# add style labels to the specified columns
mark_columns=
for i in ${daysC//|/ }; do
    mark_columns="$mark_columns
        $(printf "s/%%/C%%/%i;" $i $((i+7)) $((i+14)) )"
done

# Apply styles

$CALCMD "$@" | sed -r "

    $mark_days

    $mark_columns

    # mark days from the sets 
    s/- /-/g
    s/%($daysA)( |$)/A&/g
    s/%($daysB)( |$)/B&/g
    s/-(.( |$))/- \1/g

    # replace marks with the actual style markup
    s/C?AB%..?-(..)/$onAB\1$offAB/g
    s/C?A%..?-(..)/$onA\1$offA/g
    s/C?B%..?-(..)/$onB\1$offB/g
    s/C%..?-([^ ].| [^ ])/$onC\1$offC/g    # or /C%..?-(..)/
    s/C?%..?-(..)/\1/g    # remove unused marks

    "
===
musher0 wrote:I just did a < busybox --list > on my xenialPup, and it does not have a
< busybox awk >.
Probably the easiest way to test busybox awk is by downloading a statically compiled binary from the official site.
https://busybox.net/downloads/binaries

Code: Select all

root# busybox awk
awk: applet not found
root# chmod 755 busybox-i686 
root# ./busybox-i686 awk
BusyBox v1.28.1 (2018-02-15 14:34:02 CET) multi-call binary.

Usage: awk [OPTIONS] [AWK_PROGRAM] [FILE]...

	-v VAR=VAL	Set variable
	-F SEP		Use SEP as field separator
	-f FILE		Read program from FILE
	-e AWK_PROGRAM 
Attachments
colorcal.png
colored cal command
(12.61 KiB) Downloaded 318 times

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#94 Post by MochiMoppel »

Burunduk wrote:It is also possible to apply this technique to the entire year view
Well done!
I never thought that anyone would try to do this :lol:
Busybox sed doesn't understand multibytes chars
Well, it understands multibyte chars when inserted directly or via variable, not when the chars are represented by escape codes. But I don't see such chars in your code. I only see that busybox sed doesn't work. Can you point me to an expression where busybox sed fails?
Probably the easiest way to test busybox awk is by downloading a statically compiled binary from the official site.
https://busybox.net/downloads/binaries
These binaries seem to be compiled with CONFIG_LOCALE_SUPPORT not enabled. They are English only. It would be great if you or anyone else knows where to download a recent busybox with support for locales.

Burunduk
Posts: 80
Joined: Sun 21 Aug 2011, 21:44

#95 Post by Burunduk »

OK, this is a bit late respond but anyway...
MochiMoppel wrote:Well, it understands multibyte chars when inserted directly or via variable, not when the chars are represented by escape codes. But I don't see such chars in your code. I only see that busybox sed doesn't work. Can you point me to an expression where busybox sed fails?
There are several problems with busybox here.

Multibyte characters may appear in the cal command output and what busybox sees is a bytestring. This means that I can't use dots in the regexps.

Code: Select all

# echo "żółw" | busybox sed 's/./1/g' | wc -c
8
# echo "żółw" | sed 's/./1/g' | wc -c
5
Now, a command like s/a/b/5g fails because busybox ignores the number and replaces all the matches.

And the old versions of busybox have a bug: s/a/b/5; results in an unrecognized option error while s/a/b/5 ; (with a space before ; ) works.

And addresses like 1,+2 aren't supported by the old busybox versions.

I've rewritten the script so it should work with busybox now.

Code: Select all

#!/bin/busybox sh

# Highlights dates from two sets in the cal command output
# using distinct styles (in the month and year view).
# This version outputs an HTML document.
# Should work with busybox utilities.
# Usage: ./this_script [ [month] year ] >cal.html
# No error checking. This is just a demo. 

# cal and busybox cal insert empty lines in different places
CALCMD="busybox cal" addr=4 inc=8
#CALCMD="/usr/bin/cal -h" addr=3 inc=9

# Highlight:
# 1st set of days
daysA="1-1|1-7|12-25|12-26|12-31"
# 2nd set of days
daysB="1-2|12-31"
# columns
daysC="1|6|7"

# Styles:
# for terminal ---
#before=
#after=
#
#onA=$'\x1b[1;37;42m'    # for the 1st set
#offA=$'\x1b[0m'         # turn the style off
#
#onB=$'\x1b[1;35m'       # for the 2nd set
#offB="$offA"
#
#onAB=$'\x1b[1;37;45m'   # for the intersection of the two sets
#offAB="$offA"
#
#onC=$'\x1b[1;31m'       # for columns (if no other style applies)
#offC="$offA"
# ---

# for html ---
before="
<!DOCTYPE html>
<html><head>
<title>Kalendarz</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
.a { color: olive }
.b { color: snow; background-color: springgreen }
.ab { color: mintcream; background-color: orchid }
.c { color: tomato }
</style>
</head><body>
<pre>
"
after="
</pre>
</body></html>
"

onA='<span class="a">'
offA='<\/span>'

onB='<span class="b">'
offB="$offA"

onAB='<span class="ab">'
offAB="$offA"

onC='<span class="c">'
offC="$offA"
# ---


# Settings for the month and year view
case $# in
    0)  months=`date +%m`
        addr=2
        ;;
    1)  months='1 4 7 10'
        ;;
    2)  months=${1%%[^0-9]*}
        addr=2
        ;;
esac

# Generate repetitive parts of the sed script:

# add month labels before every 3rd char (skipping spaces between months)
mark_days=
for i in $months; do
    mark_days="$mark_days
        $addr s/[^ ]+/%-&/g
        $((addr+1)),$((addr+6)) { s/./!/22 ; s/./!/44 ; s/...?!?/%$i-&/g
            :a$i; s/(!.*%)$i/\1$((i+1))/; ta$i; s/!/ /
            :b$i; s/(!.*%)$((i+1))/\1$((i+2))/; tb$i; s/!/ /
            # s commands here are repeated until they fail
        }"
    addr=$((addr+inc))
done

# add style labels to the specified columns
mark_columns=
for i in ${daysC//|/ }; do
    mark_columns="$mark_columns
        $(printf "s/%%/C%%/%i ; " $i $((i+7)) $((i+14)) )"
done

# Apply styles

echo -n "$before"

$CALCMD "$@" | sed -r "

    $mark_days

    $mark_columns

    # mark days from the sets 
    s/- /-/g
    s/%($daysA)( |$)/A&/g
    s/%($daysB)( |$)/B&/g
    s/-(.( |$))/- \1/g

    # replace marks with the actual style markup
    s/C?AB%..?-(..)/$onAB\1$offAB/g
    s/C?A%..?-(..)/$onA\1$offA/g
    s/C?B%..?-(..)/$onB\1$offB/g
    s/C%[^-]*-( ?[^ ]+)( |$)/$onC\1$offC\2/g
    s/C?%[^-]*-//g    # remove unused marks

    "

echo -n "$after"

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#96 Post by musher0 »

Hello all.

Please find attached a variant of my "completely useless" ;) DB-type
approach above:

Code: Select all

#!/bin/bash
# /root/my-applications/bin/mois_zeros+espaces.sh
# Sketch by musher0, 26 Nov. 2018. GPL3. # Rev. 30 déc. 2018.
#
# Requires awk, replaceit, tr, and paste.
#
# Syntax should be < mois_zeros_espaces.sh month year >, but there
# is a safeguard: it defaults to current month and year if the
# script finds no positional parameters.
# 
# Please read NOTE at bottom.
####

[ "$1" ] && A=$1 || A="`date '+%m'`" # mois
[ "$2" ] && B=$2 || B="`date '+%Y'`" # année
TmP=/root/my-documents/tmp
MoiS="$TmP/mois.txt"
RPLCT="replaceit --input=$MoiS"

EnTete="`cal $A $B | grep -vE [[:digit:]] | tr " " "\t"`"
echo " " > $MoiS # For better appearance in the end.
cal $A $B | grep --color=always -vE [[:alpha:]] | tr " " ";" >> $MoiS
echo $MOIS

num="";for num in {1..9};do
     $RPLCT ";;$num" ";0$num";$RPLCT ";$num;" "0$num;"
done

i=1;for i in {1..7};do
     $RPLCT ";;;" " o "
     i="$[$i+i]"
done
# Maintenant on a un mois avec des dates de même longueur,
# tous séparés par un espace. /
# Now we have a month with dates of same length, all
# separated by a space.

cat $MoiS | tr ";" " "  > $TmP/mois.txt2

for i in {1..7}; do # séparation en colonnes (simili-BdD)
     awk '{ print $'$i' }' $TmP/mois.txt2 | tr "o" "-" > $TmP/jours$i.txt
done
for j in 1 7;do
	> $TmP/jours$j.txt2
	while read line;do 
		echo -e "\e[32m$line\e[0m" >> $TmP/jours$j.txt2
	done < $TmP/jours$j.txt
	mv $TmP/jours$j.txt2 $TmP/jours$j.txt
done

# Affichage
clear
echo; echo -e "\t\t\t\e[1;33m`cal $A $B | head -1`\e[0m"
paste /root/my-applications/bin/taquets.txt $TmP/jours*.txt
echo -e "\n\t\e[1;33m$EnTete\e[0m"

# Nettoyage
rm -f $TmP/mois.tx*
read
rm -f $TmP/jours*

exit

## NOTE ##
# To run in its own window, in your Puppy's locale:
# urxvt +sb -bg "#352e20" -g 67x13 -e mois_zeros+espaces.sh
# To run in its own window, in English:
# LANG=en_CA;urxvt +sb -bg "#352e20" -g 67x13 -e mois_zeros+espaces.sh
##########
Attachments
mois_zeros+espaces.sh.zip
(Same as above, zipped. Pls remember to make executable before running.)
(1.17 KiB) Downloaded 97 times
month+spaces-bil.jpg
(69.29 KiB) Downloaded 179 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#97 Post by MochiMoppel »

Burunduk wrote:This means that I can't use dots in the regexps.

Code: Select all

# echo "żółw" | busybox sed 's/./1/g' | wc -c
8
# echo "żółw" | sed 's/./1/g' | wc -c
5
Are you by any chance using the busybox version you recommended for download? As you've already noticed and I said before: this version is English only. Any of the Puppy busybox versions should produce the correct result of 5.

Now, a command like s/a/b/5g fails because busybox ignores the number and replaces all the matches.
It doesn't "fail", it only tries to make sense of an ambiguous command. What do you expect it to produce when you instruct it to a) replace only the 5th match? and b) replace all matches ?

When you use two contradicting flags, newer busyboxes ignore the first flag and honor only the last:

Code: Select all

# echo a..a...a...a..a | busybox sed s/a/X/3g               
X..X...X...X..X
If you change the order of the flags in the example, busybox will ignore 'g':

Code: Select all

# echo a..a...a...a..a | busybox sed s/a/X/g3
a..a...X...a..a
This is also the result I get from my older busybox 1.21.0, regardless of the g3 order.
GNU sed output is still different. Matches from the 3rd to the last are replaced, matches before the 3rd are ignored.

Bottomline: avoid ambiguous commands.

Post Reply