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

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

$
0
0
You could do it with a series of sed commands. There's probably a simpler way of doing it thought. Maybe with the date command.

Code:

atq | sed "s/Jan/01/;s/Feb/02/;s/Mar/03/s;Apr/04/;" # and so on
I just tested something that uses date to manipulate the date. You can then display the date in any form you wish. This bash script just changes the date format, rearranges the field order a bit and sorts on date.

You could of course rearrange the output again after the sort.

Code:

#!/bin/bash# Display at queue it sorted formatatq | while read id day dom month time year detailsdo  date "+%Y-%m-%d %H:%M:%S  $id  $details" -d "$day $dom $month $time $year"done | sort

Statistics: Posted by rpdom — Sun Feb 11, 2024 9:44 am



Viewing all articles
Browse latest Browse all 5251

Trending Articles