pattern-matching

How to write to a file using awk to find a string in between ( ); and add a printline after ; to print the string found?

倾然丶 夕夏残阳落幕 提交于 2019-12-06 08:04:51
I have some files in a folder that has several sqrt(x+y); functions. I want to find out what is in x+y. So I want to read the value inside sqrt(x+y ); and add a printf(x+y ); after the semicolon. I was trying this for about a month. But still cannot find a way. Please help. If you know where I can find any good tutorial or book about AWK please let me know.. Thanks. Following is the algorithm that I figured. (I am totally new to AWK) loop thro all files{ if one line starts with sqrt( start put the strings in to variable a /or array a until find ); write Print ( , concatenate, then the value ,

Java string matching with wildcards

喜欢而已 提交于 2019-12-06 07:52:53
I have a pattern string with a wild card say X (E.g.: abc*). Also I have a set of strings which I have to match against the given pattern. E.g.: abf - false abc_fgh - true abcgafa - true fgabcafa - false I tried using regex for the same, it didn't work. Here is my code String pattern = "abc*"; String str = "abcdef"; Pattern regex = Pattern.compile(pattern); return regex.matcher(str).matches(); This returns false Is there any other way to make this work? Thanks Just use bash style pattern to Java style pattern converter: public static void main(String[] args) { String patternString =

Pattern match of scala list with generics [duplicate]

一个人想着一个人 提交于 2019-12-06 07:48:38
This question already has an answer here : Pattern matching on generic type in Scala (1 answer) Closed last year . I have a class case class MyClass[T](values: List[T]) and I'm trying to create a function which will return a value based on the type of T def myFunc: T = values match { case v: List[Boolean] => false case v: List[MyType] => MyType.defaultVal case _ => throw new Exception("unsupported type") } However, I get compilation errors: Expression of type Boolean doesn't conform to expected type T Expression of type MyType.defaultVal.type doesn't conform to expected type T I guess I can

How to compare two contours of a binary pattern image?

拟墨画扇 提交于 2019-12-06 07:39:51
I'm creating a part scanner in C that pulls all possibilities for scanned parts as images in a directory. My code currently fetches all images from that directory and dumps them into a vector. I then produce groups of contours for all the images. The program then falls into a while loop where it constantly grabs images from a webcam, and generates contours for those as well. I have set up a jig for the part to rest on, so orientation and size are not a concern, however I don't want to have to calibrate the machine, so there may be movement between the template images and the part images taken.

Java Pattern/ Matcher

廉价感情. 提交于 2019-12-06 06:32:58
This is a sample text: \1f\1e\1d\020028 . I cannot modify the input text, I am reading long string of texts from a file. I want to extract the following: \1f , \1e , \1d , \02 For this, I have written the following regular expression pattern: "\\[a-fA-F0-9]" I am using Pattern and Matcher classes, but my matcher is not able find the pattern using the mentioned regular expression. I have tested this regex with the text on some online regex websites and surprisingly it works there. Where am I going wrong? Original code: public static void main(String[] args) { String inputText = "\1f\1e\1d

scala pattern match a function - how to get around type erasure

核能气质少年 提交于 2019-12-06 06:18:46
问题 I would like to pattern match a function, the problem is type erasure. Notice how in the snippet below, despite the warning issued a match occurs and a "wrong" one at that. scala> def f1 = ()=>true f1: () => Boolean scala> val fl = f1 fl: () => Boolean = <function0> scala> scala> fl match { | case fp :Function0[Boolean] => 1 | case _ => 2 | } res8: Int = 1 scala> scala> fl match { | case fp :Function0[String] => 1 | case _ => 2 | } <console>:11: warning: fruitless type test: a value of type (

Referencing / dereferencing a vector element in a for loop

血红的双手。 提交于 2019-12-06 06:18:28
In the code below, I want to retain number_list , after iterating over it, since the .into_iter() that for uses by default will consume. Thus, I am assuming that n: &i32 and I can get the value of n by dereferencing. fn main() { let number_list = vec![24, 34, 100, 65]; let mut largest = number_list[0]; for n in &number_list { if *n > largest { largest = *n; } } println!("{}", largest); } It was revealed to me that instead of this, we can use &n as a 'pattern': fn main() { let number_list = vec![24, 34, 100, 65]; let mut largest = number_list[0]; for &n in &number_list { if n > largest {

pattern matching, tuples and multiplication in Python

限于喜欢 提交于 2019-12-06 06:06:50
What is be best way to reduce this series of tuples ('x', 0.29, 'a') ('x', 0.04, 'a') ('x', 0.03, 'b') ('x', 0.02, 'b') ('x', 0.01, 'b') ('x', 0.20, 'c') ('x', 0.20, 'c') ('x', 0.10, 'c') into: ('x', 0.29 * 0.04 , 'a') ('x', 0.03 * 0.02 * 0.01, 'b') ('x', 0.20 * 0.20 * 0.10, 'c') EDIT: X is a constant, it is known in advance and can be safely ignored And the data can be treated as pre-sorted on the third element as it appears above. I am trying to do it at the moment using operator.mul, and a lot of pattern matching, and the odd lambda function... but I'm sure there must be an easier way! Can

Whole word matching with unexpected insertion in data

岁酱吖の 提交于 2019-12-06 05:18:54
I have string consider my $string = 'String need to be evaluated'; in $string I'm searching evaluated or any other word. problem is their may be insertion of some tags in string eg. Str<data>ing need to be eval<data>ua<data>ted which is unexpected. In this case how could I search for the words? here is the code I tried: my $string = 'Text to be evaluated'; my $string2 = "Te<data>xt need to be eval<data2>ua<data>ted"; # patten to match $pattern = "evaluated"; @b = split('',$pattern); for my $i(@b){ $i="$i"."\(?:<data>\)?"; print "$i#\n"; } $pattern = join('',@b); print "\n$pattern\n"; if (

Separating an Output with a Tab / Space : Perl

China☆狼群 提交于 2019-12-06 04:49:36
I am working with three text documents . The first one is the main input (Input 1) with words and the word type (Noun , Verb etc.) separated by a tab. Input 1 John N goes V to P school N . S Mary N comes V from P home N . S The second and third input text files look like this : Input 2 John Mary Input 3 to from My objective is to compare and match the second and third text files with the main input and get a output like this : Expected output: John N N goes V to P P school N . S Mary N N comes V from P P home N . S So, basically, all the three columns should be separated by tab or space.