Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6092

Other programming languages • Re: Scripting help needed - extract a part of long string into a variable

$
0
0
Thanks, I have another problem concerning the at command:

I want to list the current at queue ordered by start time.
The atq command results in this hard to read output:

Code:

 $ atq1426    Mon Feb 12 01:00:00 2024 a bosse1427    Mon Feb 12 03:00:00 2024 a bosse1417    Sun Feb 11 14:00:00 2024 a bosse1420    Sun Feb 11 18:02:00 2024 a bosse1423    Sun Feb 11 22:00:00 2024 a bosse1418    Sun Feb 11 16:00:00 2024 a bosse1419    Sun Feb 11 16:02:00 2024 a bosse1428    Mon Feb 12 05:00:00 2024 a bosse1415    Mon Feb 12 04:45:00 2024 a bosse1416    Sun Feb 11 12:00:00 2024 a bosse1425    Mon Feb 12 00:00:00 2024 a bosse1422    Sun Feb 11 19:00:00 2024 a bosse1424    Sun Feb 11 23:00:00 2024 a bosse1421    Sun Feb 11 18:00:00 2024 a bosse
So I have written a small utility atshow to fix this:

Code:

#!/bin/bashatq | awk '{print $6 " " $3 " " $4 " " $5 " " $1}' | sort
The output now becomes:

Code:

 $ atshow2024 Feb 11 12:00:00 14162024 Feb 11 14:00:00 14172024 Feb 11 16:00:00 14182024 Feb 11 16:02:00 14192024 Feb 11 18:00:00 14212024 Feb 11 18:02:00 14202024 Feb 11 19:00:00 14222024 Feb 11 22:00:00 14232024 Feb 11 23:00:00 14242024 Feb 12 00:00:00 14252024 Feb 12 01:00:00 14262024 Feb 12 03:00:00 14272024 Feb 12 04:45:00 14152024 Feb 12 05:00:00 1428
This works mostly, but on a month break like from March to April it screws up the sequence putting Apr before Mar...

So how can I add a command to change the 3-letter month names to 2-digit month numbers 01..12?
I assume it would be something to put before the sort item in my script command...
Like:

Code:

#!/bin/bashatq | awk '{print $6 " " $3 " " $4 " " $5 " " $1}' | namereplace | sort

Statistics: Posted by Bosse_B — Sun Feb 11, 2024 8:39 am



Viewing all articles
Browse latest Browse all 6092

Trending Articles