[SOLVED] How to convert the rows of data into the columns?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309
Original Poster
Rep:
Quote:
Originally Posted by PTrenholme
I started from his posted code and changed it 'till I got output that looked more like your specification.
And the resulting code corresponds to the method you used to write it: a few initial lines from H_TeXMeX_H code and all the rest yours. So I assume it’s your code inspired by H_TeXMeX_H code. (I asked you about that because I should put the information about the authors into the plugin itself as well as into the THANKS file.)
Quote:
What H_TeXMeX_H's code seemed to be doing was trying to write the HH|MM|SS values as six-binary-digit numbers. Somewhat harder to "read," but a "true" binary clock.
Something that you call “six-binary-digit numbers clock” I call “6-bits binary clock” (I mean each number consists of 6 bits). The vertical binary clock for wminfo can be only 4-bits clock. The horizontal binary clock for wminfo can be 6-bits clock and thanks to two additional lines it can display also the month and the day.
As for the binary watches I prefer 4-bits versions because they look cooler and are easier to read.
Quote:
(Being 72 years old, I'm not mentally flexible enough to understand binary notation as "intuitively" as decimal. )
At the beginning I asked: “Is it the reverse numbers notation or something like that?”. Then I checked your profile. According to the picture you indeed can be in your forties, fifties, etc. (The picture is blurred so it’s difficult to determine the age more precisely.) Well, yesterday I told my friend about that thread. She smiled and said: “That must be very young people”. I think youth is a state of mind. I know a lot of people much younger than me that look, behave, and – as a result – are older than me.
bash-4.1$ ./do-timings.sh 100
time for 00-nothing : 0.31 real, 0.12 user, 0.09 sys, 67.92% CPU
time for 07-rotate1-w1k0 : 3.13 real, 0.41 user, 0.79 sys, 38.48% CPU
time for 08-rotate-multi-PTrenhol: 3.10 real, 0.47 user, 0.82 sys, 41.89% CPU
time for 15-gawk-ntubski : 0.46 real, 0.22 user, 0.20 sys, 93.47% CPU
time for 17-simpler-time-vars-w1k: 2.08 real, 0.43 user, 0.79 sys, 58.84% CPU
time for 18-heredoc-grail : 1.28 real, 0.79 user, 0.32 sys, 87.09% CPU
time for 21-arg-grail : 1.16 real, 0.77 user, 0.32 sys, 94.91% CPU
time for 23-no-transpose-grail : 1.14 real, 0.72 user, 0.32 sys, 91.84% CPU
time for 25-bash-PTrenholme : 0.59 real, 0.30 user, 0.12 sys, 72.79% CPU
time for 29-bash-grail : 0.53 real, 0.30 user, 0.11 sys, 77.47% CPU
time for 47-binclock : 0.06 real, 0.00 user, 0.01 sys, 21.52% CPU
bash-4.1$ ./47-binclock
HH|MM|SS
* |**|
|* |
*| |**
| *|
echo -e "$VAR1\n$VAR2\n$VAR3" \
|awk -F "" 'BEGIN {b[0]="A";b[1]="B"} \
{for (i=1; i<=NF; i++) a[i]=a[i]b[$i]} \
END {i=1; while (i in a) {print a[i]; i++;}}'
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309
Original Poster
Rep:
H_TeXMeX_H, PTrenholme, grail, and ntubski,
Thanks to ntubski the next wminfo release can run not only bash scripts but also scripts written in the other languages as well as binary programs. I tested all your scripts once again running them as wminfo plugins. Two of them written in C have the best performance. Five following written in bash or Ruby have slightly worse performance. One written in bash has the worst performance.
I put the current pre-release of wminfo here: http://linux-bsd-unix.strefa.pl/wminfo-pre3.1.0.tar.gz. (Before releasing it I have at least update some Internet-dependent plugins and test the program and plugins in some other distribution.)
Here’s an excerpt from wminfo documentation:
Quote:
Eight different 4-bits vertical binary clock plugins -- two from plugins.binary directory, five from plugins.system directory, and one from samples directory -- do exactly the same and are the result of the discussion in the Programming section of LinuxQuestions.org (http://www.linuxquestions.org).
A few debaters -- H_TeXMeX_H, PTrenholme, grail, ntubski, and w1k0 -- wrote the 4-bits vertical binary clocks designed as the plugins for wminfo (some of them wrote a few versions).
Two binary clocks (written in C):
- binclock-vertical-1.bin by H_TeXMeX_H
- binclock-vertical-2.bin by PTrenholme
are in the plugins.binary directory (these are the plugins using the CPU power the least).
Five binary clocks (three written in bash and two written in Ruby):
- binclock-vertical-3.wmi by grail
- binclock-vertical-4.wmi by Noam Postavsky aka ntubski
- binclock-vertical-5.wmi by grail
- binclock-vertical-6.wmi by PTrenholme
- binclock-vertical-7.wmi by grail
are in the plugins.system directory (these are the plugins using the CPU power moderately).
One binary clock (written in bash):
- binclock-vertical-8.wmi by Cezary M. Kruk aka w1k0
is in the samples directory (this is the plugin using the CPU power the most).
I added to all of them the necessary comments as well as the procedures allowing to switch on and switch off the label and the separators.
Here are the results of the tests of the performance:
Code:
The CPU usage of the respective plugins used by wminfo is the following:
plugin | author | language | CPU usage | median
------------------------+------------+----------+-------------+-------
binclock-vertical-1.bin | H_TeXMeX_H | C | 1.3% - 1.5% | 1.2%
binclock-vertical-2.bin | PTrenholme | C | 1.3% - 1.6% | 1.2%
------------------------+------------+----------+-------------+-------
binclock-vertical-3.wmi | grail | bash | 2.0% - 2.3% | 1.9%
binclock-vertical-4.wmi | ntubski | bash | 2.0% - 2.6% | 1.9%
binclock-vertical-5.wmi | grail | Ruby | 1.8% - 2.3% | 2.0%
binclock-vertical-6.wmi | PTrenholme | bash | 2.2% - 2.4% | 2.0%
binclock-vertical-7.wmi | grail | Ruby | 2.0% - 2.5% | 2.0%
------------------------+------------+----------+-------------+-------
binclock-vertical-8.wmi | w1k0 | bash | 3.8% - 4.4% | 3.9%
(The tiny median difference between 1.9% and 2.0% means in practice the same
performance taking into consideration possible inaccuracy of the
measurement.)
The performance was mesured with the command:
top -b -n 40 | grep '^Cpu' | sort -n
Thank you guys once again for your kind assistance.
***
This is my post #999. With the next post I’ll reach the title of “Senior Member”. Thanks to that thread and the private mailing with ntubski I learned a lot and came closer to be a senior.
My question from post #24 remains current: “Is it the most active solved thread ever?”.
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309
Original Poster
Rep:
@PTrenholme,
I hoped my post #1000 will be wiser but the harsh true is that writing one post can change Member into Senior Member but can’t change layman into expert.
I can’t run your script.
Your script produces the following result:
./bin_clock.gawk
Code:
./bin_clock.gawk: line 1: BEGIN: command not found
./bin_clock.gawk: line 4: bin[0][1]=b: command not found
.
.
.
./bin_clock.gawk: line 13: bin[9][4]=a: command not found
./bin_clock.gawk: line 17: syntax error near unexpected token `('
./bin_clock.gawk: line 17: ` print strftime("%H|%M|%S")'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.