There is a way to parse from smarty? - smarty

folks! At php I have such code:
'homeSize' => Image::getSize('home')))
So, there is a way to parse it from smarty?
For example:
'largeSize' => Image::getSize('large')

Using the modifier "getimagesize" you can get all required info about an image.
I wrote an example on how to split the result in to separate variables here:
http://www.i-do-this.com/blog/49/Getting-the-image-dimensions-in-smarty

So, I have done it myself - to parse from Smarty: {assign var='largeSize' value=Image::getSize('large')}

Related

Can I use shell script to read a file, find a variable in that file and store it to use in another script?

I'd like to read a yaml file and find a specific variable, then store that variable's value.
So it's something like:
- variable1:
variable2:
- "value"
variable3:
- ...
and I want to grab variable2's value, which also happens to be a file path. I'd like to be taken to that file path as well, so using the value to locate the value at that file path. Is that possible in shell script without a 3rd party library/plugin?
If not, what's the best approach to act on a yaml config with this objective?
Any help would be highly appreciated. Cheers!
Only way to parse yaml with shell could be that you need to implement your own script to parse yaml. Following is a helpful blog.
https://linuxhint.com/parse-yaml-file-bash/

Bash bad variable substitution to extract a major number from a release

I have a CI_COMMIT_TAG variable with the following sample value: v12.23.34.
I would like to extract the major part number of the tag on CI_RELEASE_MAJOR, meaning 12.
Following this documentation, I did the following:
export CI_RELEASE_MAJOR=${${CI_COMMIT_TAG#v}%%.*}
This is working on zsh, but not on bash, giving the following error:
CI_RELEASE_MAJOR=${${CI_COMMIT_TAG#v}%%.*}: bad substitution
Why is it not working on bash and what is the proper way to achieve what I want?
Thanks!
Why is it not working on bash
Because it's not possible to nest expansions like that.
what is the proper way to achieve what I want?
The proper way is:
tmp=${CI_COMMIT_TAG#v}
CI_RELEASE_MAJOR=${tmp%%.*}
An alternative is to use regular-expression matching.
[[ $CI_COMMIT_TAG =~ v([^.])*\. ]]
export CI_RELEASE_MAJOR=${BASH_REMATCH[1]}

How to delete a part of a string between two patterns including one of them

I have a CSV document like this:
RL|S1|C19.concoct_part_0 concoct.26
RL|S1|C26.concoct_part_4 concoct.7
RL|S1|C26.concoct_part_5 concoct.7
I want it to be like this:
RL|S1|C19 concoct.26
RL|S1|C26 concoct.7
RL|S1|C26 concoct.7
How do I do it in Vim?
Thanks to #oguz ismail the solution is the following
:%s/\.[^\t]*//
Using command line mode you can run:
:%norm f.dt<space><enter>
Note: you must to type space and enter instead of writing it.

Multi-line JSON read using Apache PIG

I have a JSON file and want to read using Apache Pig.
I tried using the regular JSONLOADER, but looks like JSONLOADER works only with single line JSON. Then I tried with Elephant-Bird. But I am still not able to see the results correctly. Can any one please suggest a solution?
Input :
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
Note : I dont want to convert the input in to a single line.
Script:
A = LOAD 'input' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad');
B = FOREACH A GENERATE FLATTEN($0#'employees');
Dump B;
Expected result should be :
([firstName#John,lastName#Doe])
([firstName#Anna,lastName#Smith])
([firstName#Peter,lastName#Jones])
As mentioned in the comments by siva, the answer is basically that you do need to change your input to a single line.
JsonLoader or elephantbird loader will always works only with single
line . It will not work with multiline. You need to convert your input
to single line before passing to pig. One workaround would be write a
shell script and call the logic to replace multiline to single line
using 'SED' command and then call the pig script in the shell script.
This link will help you how to call pig thru shell script.

Looking for an alternative to eval

I'm new to ruby however it isn't really that drastic of a change coming from perl, anyways 've written a simple script to convert my gobs of perl Data::Dumper output into yaml configs, my problem is I'm using eval to accomplish this and seeing as I may like others to use this script one day I would like to eliminate eval for something more sane.
example:
input file contains
$VAR1 = { 'object' => { 'some_key' => 'some_value' } }
method to read it in
# read in file here ...
eval( stringified_file )
print $VAR1.to_yaml
output
object:
some_key: some_value
Thanks :)
On the Perl side you can output your data structures to YAML (I like YAML::Syck for this), and then read the data in as YAML on the Ruby side. That way you won't need to do an eval.
If for you're unable to change the source application to output YAML, use Kernel#load:
require 'yaml'
load 'dumped_file', true
puts $VAR1.to_yaml

Resources