[Execute command] problem: new line on the end of output

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
kamil_w
Posts: 50
Joined: 22 Oct 2013 19:01

[Execute command] problem: new line on the end of output

Post by kamil_w » 19 Mar 2019 16:44

Hi,
I am trying to create "an application" in Automagic with possibility to change the language of UI. So I have some text files in format:

variable_name=text string

To convert text from files into global_variables I use an action "Execute command" with command:

grep "global_variable" /patch/{value}.lang | cut -d "=" -f 2

And in field "Variable to store the standard output" I put "global_variable".

It works, but the global_variable is filled by text with new line which cause me some issues.

Instead of:
"Text string"

I get

"Text string

"

Does anyone know how to fix it or how to get strings for variables from txtfile in different way?

kamil_w
Posts: 50
Joined: 22 Oct 2013 19:01

Re: [Execute command] problem: new line on the end of output

Post by kamil_w » 19 Mar 2019 22:23

I found solution. :)

Action script:
global_value = trim(global_value)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: [Execute command] problem: new line on the end of output

Post by Desmanto » 20 Mar 2019 15:48

To get text from files, we usually just action init variable text file, although that is limited to 1 MB files only. To get the string you want, probably it is much easier to use regex. findAll() is one the function I use a lot to parse those kind of text.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

kamil_w
Posts: 50
Joined: 22 Oct 2013 19:01

Re: [Execute command] problem: new line on the end of output

Post by kamil_w » 21 Mar 2019 00:29

Thanks.
Works like a charm. :)

Post Reply