How can i find a pattern and format it into desired output in Linux [closed] - regex

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
I have file a.txt with content:
/**
* #brief Warnings
* Warnings (probably can be safely ignored). These should normally not happen,
* but if they do they may give extra information when diagnosing a fault.
*/
ERROR_LINE(error_WARNING, 100)
// Description of warning 170
ERROR_LINE(warning_170, 170)
// Description of warning 180. Description of warning 180. Description of
// warning 180. Description of warning 180. Description of warning 180.
ERROR_LINE(xxx_180, 180)
// Description of warning 190
ERROR_LINE(warning_190, 190)
What linux command line tool should i use to conver it into:
* /## Warnings
*
* Warnings (probably can be safely ignored). These should normally not happen,
* but if they do they may give extra information when diagnosing a fault.
*
Code | Description
* ------------ | -------------
* 170 | Description of warning 170
* 180 | Description of warning 180. Description of warning 180. Description of warning 180. Description of warning 180. Description of warning 180.
* 190 | Description of warning 190
I have tried various tools without any success

You can use the command awk like this :
awk '/\/\*\*/{print "## Warnings\n\nWarnings (probably can be safely ignored). These should normally not happen,\nbut if they do they may give extra information when diagnosing a fault.\n"} /ERROR_LINE/{gsub(/\)/,"",$0); printf("* %s | ", $NF); getline; print $0"\n"}' a.txt
The output
## Warnings
Warnings (probably can be safely ignored). These should normally not happen,
but if they do they may give extra information when diagnosing a fault.
* 100 | // Description of warning 170
* 170 | // Description of warning 180. Description of warning 180. Description of
* 180 | // Description of warning 190
* 190 | ERROR_LINE(warning_190, 190

Related

Google script regex match without results [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
I have the following bit in a google script that parses pdfs:
function extractPDFtext(text){
const regexp = /[w,W,s,S]*(\d{3}).?(\d{3}).?(\d{3}).?(\d{3})?.?(\d{3})?[\w\W]*?(\d+.\d+)/gm;
try{
let array = [...text.match(regexp)];
return array;
}catch(e){
let array = ["No items found"]
return array;
}
};
The existing regex partially works (because the pdf's are not all equal) and so I have to restrict the search/matching between words/results and when I try to do it, I get no results. I would like to retrieve the digits related to Reference and Amount tags, while ignoring any words and digits in between. And it's here that I'm having some trouble because on regex101 I get the full match + the correct capturing groups but once on the script, I get no results.
This is a regex example based on what was suggested on another question of mine but in the end has the same problem as any of my other attempts:
^Reference\b[^\d\n]*[\t ](\d{3})[\t ]*(\d{3})[\t ]*(\d{3})[\t ]*(\d{3})[\t ]*(\d{3})(?:\n(?!Amount\b)\S.*)*\nAmount\b[^\d\n]*[\t ](\d+(?:,\d+)?)\b
So I'm wondering if the problem is with the regex or with the script and how to solve in any of those circumstances.
Below, there's some dummy text example of the variable text where the regex is being used on, baring in mind that it can have more words after each "tag" (example: Reference of something // Amount of first payment:); it can have : or not.
Some dummy text that may have words in common like `reference` or `amount` throughout the document
Reference: 245 154 343 345 345
Entity: 34567
Amount: 11,11
Payment date: 14/07/2022
Some more text
Maybe your trying to do too much with one command. Try breaking it up as I show below.
console.log(text);
let ref = text.match(/Reference.+/gm);
if( ref.length > 0 ) {
ref = ref[0].match(/\d.+/);
console.log(ref[0]);
}
ref = text.match(/Amount.+/);
if( ref.length > 0 ) {
ref = ref[0].match(/\d.+/);
console.log(ref[0]);
}
Execution log
8:55:50 AM Notice Execution started
8:55:50 AM Info Some dummy text that may have words in common like `reference` or `amount` throughout the document
Reference: 245 154 343 345 345
Entity: 34567
Amount: 11,11
Payment date: 14/07/2022
Some more text
8:55:50 AM Info 245 154 343 345 345
8:55:50 AM Info 11,11
8:55:50 AM Notice Execution completed

Cachegring file very small

I am new to profiling. I am trying to profile my PHP with xdebug.
The cachegrind file is created but has no significant content
I have set xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_name = cachegrind+%p+%H+%R.cg
I call my page with additional GET parameter ?XDEBUG_PROFILE=1
My cachegrind file is generated but has no significant content
Here is my output:
version: 1
creator: xdebug 2.7.0alpha1 (PHP 7.0.30-dev)
cmd: C:\WPNserver\www\DMResources\Classes\VendorClasses\PHPMySQLiDatabase\MysqliDb.php
part: 1
positions: line
events: Time Memory
fl=(1)
fn=(221) php::mysqli->close
1244 103 -14832
fl=(42)
fn=(222) MysqliDbExt->__destruct
1239 56 0
cfl=(1)
cfn=(221)
calls=1 0 0
1244 103 -14832
That's it - I must be missing something fundamental.
I think you hit this bug in xdebug.
As suggested by Derick in the issue tracker, you can workaround this by adding %r to the profiler output name. eg: xdebug.profiler_output_name = cachegrind+%p+%H+%R+%r.cg
(with %r adding a random number to the name)

Baron Error with Pyomo: NonLinearity Error in POW expression

I am trying to solve a nonlinear optimization problem in Pyomo with Baron.
The solving works fine when using solvers like ipopt, bonmin, couenne etc.
When using Baron I get the following error:
===========================================================================
BARON version 18.5.9. Built: WIN-64 Wed May 9 22:52:08 EDT 2018
BARON is a product of The Optimization Firm, LLC. http://www.minlp.com/
BARON: NonLinearity Error in POW expression
ERROR: Solver (baron) returned non-zero return code (9)
ERROR: See the solver log above for diagnostic information.
Traceback (most recent call last):
File "C:/Users/public.THREADRIPPER/Desktop/CGAM_SWP.py", line 602, in <module>
Results = opt.solve(comp, tee=True, keepfiles=True)
File "C:\Anaconda3\lib\site-packages\pyomo\opt\base\solvers.py", line 626, in solve
"Solver (%s) did not exit normally" % self.name)
pyutilib.common._exceptions.ApplicationError: Solver (baron) did not exit normally
Process finished with exit code 1
Any idea where the problem is?
Thanks!
I'm not sure how urgent the matter still is but I experienced the same issue as you. Actually, in the BARON.py file there is a note regarding this error message here (hope you can see my screenshot, for some reason I am not allowed to upload pictures).
Anyway, I experience the problem in a different way than noted in the BARON.py file. In my case I am using the pyomo.core.base.symbolic.differentiate() function to create first derivates of functions which are to the power of (1/3) which then result in negative exponents which baron apparently has issues with. If I manually exchange the negative exponents with division, it seems to work.
Hope this helps you.
UPDATE: I have to update my comment because it is not negative exponents (per se) which in my case caused the error message of interest ("NonLinearity Error in POW expression", Solver (baron) returned non-zero return code (9)) but it is the way I had introduced them in the input file. In the baron manual there is an example of the case (see screenshot) I am referring to.
So in my case the error message was caused because I had constraints defined like this:
... * ( -241.5 + 0.5 * x12 ) ^ -1.0 * ( x1 - x6 ) ^ -1.0 * ( -483.0 + x12 + x1 - x6 ) ^ -1.0 * ...
which are according to the baron manual misinterpreted by the solver compared to my intention. Actually, in my case a x^y situation was created with nested negative exponential expressions which probably could be solved by baron if it is introduced differently (see next screenshot). However, if I include parentheses around the exponents, to get the expressions I am aiming for, i.e.:
... * ( -241.5 + 0.5 * x12 ) ^ (-1.0) * ( x1 - x6 ) ^ (-1.0) * ( -483.0 + x12 + x1 - x6 ) ^ (-1.0) * ...
it works perfectly fine.

SAS: build linear regression model

I need to do build a simple regression model around the productivity of various land units in SAS but I am fairly new to it. I have the following parameters:
Prodbanana / ELEVATION / SLOPE / SOILTYPE
The productivity vaules of banana are in kg/ha; The elevation and slope parameters are already classified (6 classes) as well as SOILTYPE (6 classes)
The model should be: Productivity = x1* ELEVATION + x2*SLOPE + x3*SOILTYPE
I tried so far:
proc glm data=Work.Banana2;
class ELEVATION SLOPE SOILTYPE;
model Prodbanana = ELEVATION + SLOPE + SOILTYPE;
run;
But it returns the following error:`
45 proc glm data=Work.Banana2;
46 class ELEVATION SLOPE SOILTYPE;
47 model Prodbanana = ELEVATION + SLOPE + SOILTYPE;
-
22
-----
202
NOTE: The previous statement has been deleted.
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, (, *, -, /, #,
CHARACTER, CHAR, NUMERIC, |.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
48 run;`
Any suggestions?
cheers
The addition operator is unnecessary. You can find a quick guide to model specification syntax
here. Works across SAS regression procedures.

How can I show print statements in debug mode of OPNET Modeler?

I'm writing C++ code in OPNET Modeler.
I try to simulate my scenario in debugger mode & I need to trace the function that I wrote it. I need to show print statements which I put it in my code.
I used in debugger mode: ***ltr function_name()*** then ***c***
But the result looks like:
Type 'help' for Command Summary
ODB> ltr enqueue_packet()
Added trace #0: trace on label (enqueue_packet())
ODB> c
|-----------------------------------------------------------------------------|
| Progress: Time (1 min. 52 sec.); Events (500,002) |
| Speed: Average (82,575 events/sec.); Current (82,575 events/sec.) |
| Time : Elapsed (6.1 sec.) |
| DES Log: 28 entries |
|-----------------------------------------------------------------------------|
|-----------------------------------------------------------------------------|
| Progress: Time (1 min. 55 sec.); Events (1,000,002) |
| Speed: Average (69,027 events/sec.); Current (59,298 events/sec.) |
| Time : Elapsed (14 sec.) |
| DES Log: 28 entries |
|-----------------------------------------------------------------------------|
|-----------------------------------------------------------------------------|
| Progress: Time (1 min. 59 sec.); Events (1,500,002) |
| Speed: Average (51,464 events/sec.); Current (34,108 events/sec.) |
| Time : Elapsed (29 sec.) |
| DES Log: 28 entries |
|-----------------------------------------------------------------------------|
|-----------------------------------------------------------------------------|
| Simulation Completed - Collating Results. |
| Events: Total (1,591,301); Average Speed (48,803 events/sec.) |
| Time : Elapsed (33 sec.); Simulated (2 min. 0 sec.) |
| DES Log: 29 entries |
|-----------------------------------------------------------------------------|
|-----------------------------------------------------------------------------|
| Reading network model. |
|-----------------------------------------------------------------------------|
I need to show the print statements in my code.
Where it has to be appeared?
Is there any step before run the simulation to insure that OPNET debugger using Visual Studio & go through my code??
OPNET Modeler provides the following commands to print trace output:
op_prg_odb_print_major() Prints a sequence of strings to the standard output device, in the format of ODB trace statements starting at the major indentation level.
op_prg_odb_print_minor() Prints a sequence of strings to the standard output device, in the format of ODB trace statements at the minor indentation level.
op_prg_text_output() Prints a sequence of user-defined strings to the standard output device.
For example:
if (op_prg_odb_ltrace_active ("tcp_window")) {
/* a trace is enabled, output Window-Related Variables */
char str0[128], str1[128], str2[128];
sprintf (str0, "rcv requests pending : (%d)", num_rcvs_allowed);
sprintf (str1, "local receive window : (%d)", receive_window);
sprintf (str2, "remote receive window : (%d)", remote_window);
op_prg_odb_print_major ("Window-Related Variables", str0, str1, str2, OPC_NIL);
sprintf (str0, "send unacked : (%d)", send_unacked);
sprintf (str1, "send_next : (%d)", send_next);
sprintf (str2, "receive next : (%d)", receive_next);
op_prg_odb_print_minor (str0, str1, str2, OPC_NIL);
}
Example output as it appears on the standard output device:
| Window-Related Variables
| rcv requests pending : (3)
| local receive window : (6400)
| remote receive window : (10788)
| send unacked : (4525)
| send_next : (5000)
| receive_next : (1200)
[Code taken from OPNET Modeler documentation.]
Note: I am guessing that you are modifying the standard models and are using the stdmod Repository. If this is the case, your code is not being compiled and you will not see any print statements in the debugger. See preference "Network simulation Repositories" to see if you are using a repository instead of compiling your own code.
I don't have much idea about what your trying to do , but i think you can output statements directly to a debugger for C++ code using
OutputDebugStringA("Your string here");
or just
OutputDebugString("Your string here");
Hope this helps!