Yaml numeric keys: can't start with zero? - twig

Let's say I have this .yml file used for Symfony2 i18n
month:
01: Jan
02: Feb
03: Mar
04: Apr
05: May
06: Jun
07: Jul
08: Aug
09: Sep
10: Oct
11: Nov
12: Dec
In twig, for tanslation, I will use something like
{% set month = my_date|date("m") %}
{{ ('month.'month)|trans }}
In this scenario, all months starting with "0" will not be translated. I've read yaml documentation (not so deep, but I've searched on the internet) and I haven't find any page saying that a key couldn't start with zero (and it seems not to be possible for a key start with zero).
So, my questions are:
Is that a yaml issue?
If this isn't an issue, why keys could not start with "0"?

As #Maerlyn commeted, you should encapsulate your keys with quotes to avoid loosing preceding and following zeros.

Related

Why GNU Global doesn't index Pascal files of a project?

I'm trying to index the Pascal files of a project, on Linux (modern Ubuntu).
I've followed the instructions, but I'm very confused because of several factors.
The procedure I've applied is:
$ apt install global exuberant-ctags
$ python3 -m pip install pygments
$ gtags --version
gtags (GNU GLOBAL) 6.6.4
Now, things start to get confusing, because first, there is no gtag.conf anywhere in the system.
There is a /usr/share/doc/global/examples/gtags.conf.gz, which says, at the top:
Basically, GLOBAL doesn't need this configuration file ('gtags.conf'),
because it has default values in itself. [...]
I ignore this comment, and run:
gzip -dc /usr/share/doc/global/examples/gtags.conf.gz > /tmp/gtags.conf
export GTAGSCONF=/tmp/gtags.conf
export GTAGSLABEL=pygments
gtags -v
I can see from the output:
[Sat Aug 13 13:57:58 CEST 2022] Gtags started.
Using configuration file '/tmp/gtags.conf'.
Using configuration label 'pygments'.
Using plug-in parser.
[Sat Aug 13 13:57:58 CEST 2022] Creating 'GTAGS' and 'GRTAGS'.
[1] extracting tags of FILE1.ASM
[2] extracting tags of FILE2.ASM
[Sat Aug 13 13:57:58 CEST 2022] Done.
That no PAS files are included.
I try to follow the instructions from the official tutorial:
find . -name '*.PAS' > /tmp/list
gtags -vf /tmp/list
And the output doesn't include any file, essentially:
[Sat Aug 13 14:01:44 CEST 2022] Gtags started.
Using configuration file '/tmp/gtags.conf'.
Using configuration label 'pygments'.
Using '/tmp/list' as a file list.
Using plug-in parser.
[Sat Aug 13 14:01:44 CEST 2022] Creating 'GTAGS' and 'GRTAGS'.
[Sat Aug 13 14:01:44 CEST 2022] Done.
Now, I try to rename the PAS files to pas (or add .PAS to the gtags.conf file). It seems to get better:
$ gtags -v
[Sat Aug 13 14:04:57 CEST 2022] Gtags started.
Using configuration file '/tmp/gtags.conf'.
Using configuration label 'pygments'.
Using plug-in parser.
[Sat Aug 13 14:04:57 CEST 2022] Creating 'GTAGS' and 'GRTAGS'.
[1] extracting tags of FILE1.ASM
[2] extracting tags of FILE2.pas
[... all relevant files ...]
[Sat Aug 13 14:04:58 CEST 2022] Done.
But gtags seems no to index anything relevant, since this:
$ gtags -vf FILE2.pas
results in a big list of lines marked as not found. ignored.
What confuses me is that it seems that Global is not able to parse Pascal files for some reason, but on the other hand, I don't get any error (which I suppose is relate to Pygments).
The "gtags" command generates the index.
gtags -vf relevant.lst expects a list of files inside relevant.lst.
To query contents of a file, you must use "global" command.
E. g. global -c function_na should give you completed function_name as result (provided there is such function in your code)

Convert GMT timestamp to local time using Bash and GNU tools

I am getting results to a log file that contain a line like this:
date: Sat, 12 Dec 2020 22:33:34 GMT
I want to use only Bash and GNU tools on my Ubuntu Linux box if possible to convert this to my local time "Eastern" or Michigan/Detroit. It should work even on Daylight Saving Time or if past/before Midnight. I want the result stored in a variable in a common format such as 2020-12-01 for December 1, 2020. One variable for the military time, a second for the date would probably be best. I can calculate the "Sat/Sun/Mon/etc" and probably don't need that anyway.
I would expect the "cut" command could separate out the different fields, but how to deal with GMT?
#!/bin/bash
datime="date: Sat, 12 Dec 2020 22:33:34 GMT"
#magic happens
echo dalocaltime is $dalocaltime and dalocaldate is $dalocaldate
results:
dalocaltime is 14:20:33 and dalocaldate is 2020-01-30
This works for me, but I can't explain the ${datime#* } part
datime="date: Sat, 12 Dec 2020 22:33:34 GMT"
dalocaltime=$(date -d "${datime#* }" '+%R')
dalocaldate=$(date -d "${datime#* }" '+%Y-%m-%d')
echo dalocaltime is $dalocaltime and dalocaldate is $dalocaldate

How to convert to / get RFC822 date in bash/linux?

Looking at date's man page, I couldn't find a standard way to convert to rfc822 (eg: from unix timestamp). I took a brief look at the spec, but I don't know enough about the subject matter to get the format right. Is there a easy way to convert to rfc822 with standard linux terminal tools?
According to man 1 date:
-R, --rfc-email
output date and time in RFC 5322 format.
Example: Mon, 14 Aug 2006 02:34:56 -0600
And it looks like RFC5322:
[...] is a revision of Request For Comments (RFC) 2822, which itself superseded
Request For Comments (RFC) 822 [...]
Short answer use date -R (and -d #<unix> for the unix timestamp). For example, in my machine just now:
$ date -R
Mon, 11 Sep 2017 20:41:30 +0200
$ date -R -d #1505155314
Mon, 11 Sep 2017 20:41:54 +0200

Getting specific part of output in Linux

I have an output from a shell script like this:
aaa.sh output
Tue Mar 04 01:00:53 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 04 07:21:52 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 04 13:17:16 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 04 16:56:01 2014
SQL> ALTER DISKGROUP fra ADD DISK '/dev/rhdisk20'
Wed Mar 05 00:03:42 2014
Time drift detected. Please check VKTM trace file for more details.
Wed Mar 05 04:13:39 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 05 05:56:07 2014
GMON querying group 3 at 10 for pid 18, osid 27590856
GMON querying group 3 at 11 for pid 18, osid 27590856
I need to get the part, beginning from today's date:
Wed Mar 05 00:03:42 2014
Time drift detected. Please check VKTM trace file for more details.
Wed Mar 05 04:13:39 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 05 05:56:07 2014
GMON querying group 3 at 10 for pid 18, osid 27590856
GMON querying group 3 at 11 for pid 18, osid 27590856
You can get the date in the correct format like this:
today=$(date +'%a %b %d')
and then search for it like this:
grep "$today" aaa.sh
If there are lines from today without a date, such as your GMON lines, you could add -A to say how many lines after the match you want and use a big number:
grep -A 999999 "$today" aaa.sh
If you are on AIX and there is no -A option, use sed like this:
today=$(date +'%a %b %d')
sed -n "/${today}/,$ p" aaa.sh
Explanation:
That says store today's date in the variable today in the format "Wed Mar 05". Then search, without printing anything (-n) till you find that date, From that point on, till the end of file ($) print all lines (p).
I think I have an easy solution:
Get date to output the date in a format that would match the date in the file (check man date on formatting options). Since we don't want to match the hours/minutes/seconds we have to call date twice: once for the weekday/month/day half and once for the year half on the end of the full date. Between these two halves we match the horus/minutes/seconds with .* regex.
Then do:
aaa.sh | grep -E '`date --only-weekday-month-day`.*`date --only-year`' -A 999999
though I am using answer by NewWorld it can be modified as,
convert output of date similar to your file format
suppose in variable 'D'you get that output
sed '1,/${D}/d' aaa.sh
that will output all lines after match date match.
example: suppose you get D="Wed Mar 05 00:03:42 2014"
output will be as expected.
You can use
tail -n 7 filename
for getting the desired output . It will basically give you the last seven lines of the text file named filename .
For getting solution from today's date you can use :
k=$(date +"%a %b %d")
g=$(grep -nr "$k" in|cut -f1 -d:|head -1)
total=$(wc -l<in)
l=`expr $total - $g + 1
tail -n$l in
Try
sed -n '/Wed Mar 05/,$p' aaa.sh
Here -n means "don't print anything unless specified to".
First appearance of a line that matches the expression /Wed\ Mar\ 05/ till the end of the file, will be printed(p)"

How to remove terminal control escape sequences in the file?

I got a log from remote linux computer. It looks like:
2013-10-23T08:19:05+0300 Last login: Wed Oct 23 08:17:38 EEST 2013 from 10.9.167.55 on pts/0
2013-10-23T08:19:05+0300 Last login: Wed Oct 23 08:19:05 2013 from 10.9.167.55^M
2013-10-23T08:19:07+0300 ^[[?1034h-bash-4.1$ date
2013-10-23T08:19:07+0300 Wed Oct 23 08:19:07 EEST 2013
2013-10-23T08:19:08+0300 -bash-4.1$ ls
2013-10-23T08:19:08+0300 ^[[0m^[[01;34m99^[[0m #avail.info ^[[01;34mgmoTemp^[[0m raml21.dtd SNMP4JTestAgentBC.cfg
2013-10-23T08:19:08+0300 an_mainHost_localhost_20131023081654000136.xml #avail.info~ gsh.txt ^[[01;34mresults^[[0m
2013-10-23T08:19:09+0300 ^[[m-bash-4.1$ exit
2013-10-23T08:19:09+0300 logout
But it should be:
Last login: Wed Oct 23 08:17:38 EEST 2013 from 10.9.167.55 on pts/0
Last login: Wed Oct 23 08:19:05 2013 from 10.9.167.55
-bash-4.1$ date
Wed Oct 23 08:19:07 EEST 2013
-bash-4.1$ ls
99 #avail.info gmoTemp raml21.dtd SNMP4JTestAgentBC.cfg
an_mainHost_localhost_20131023081654000136.xml #avail.info~ gsh.txt results
-bash-4.1$ exit
logout
The messy codes are terminal control escape sequences, you can use command "infocmp xterm" and "man terminfo" to get more details.
My question is how can I remove these terminal control escape sequences in the file?
Thanks a lot!
Simple way to remove most parts of the control character is using the command below in vim:
:%s/<escape-key>\[[0-9;]*m/ /g
Press Ctrl+V followed by esc-key for the <escape-key> character above. Everything else is the same literal key as in your keyboard.
i use a pipe or direct sed like this
sed 's/[^[:print:]]\[[^a-zA-Z]*[a-zA-Z]//g' YourFile
I solved this issue using lots of regular expressions according to http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Resources