Best way to get all digits from a string [duplicate]
Do you need to use a Regex? return new String(input.Where(Char.IsDigit).ToArray());
Do you need to use a Regex? return new String(input.Where(Char.IsDigit).ToArray());
Or this pyparsing version: >>> from pyparsing import nestedExpr >>> txt = “{ { a } { b } { { { c } } } }” >>> >>> nestedExpr(‘{‘,’}’).parseString(txt).asList() [[[‘a’], [‘b’], [[[‘c’]]]]] >>>
One way using GNU awk and FPAT awk ‘BEGIN { FPAT = “([^, ]+)|(\”[^\”]+\”)” } { sum+=$3 } END { print sum }’ file.txt Result: 192
Try this: awk -F”,” ‘{print $1}’ data.txt It will split each input line in the file data.txt into different fields based on , character (as specified with the -F) and print the first field (column) to stdout.
One approach that you can use on smaller files that can fit into your memory twice: $data = file(‘myfile’); // reads an array of lines function replace_a_line($data) { if (stristr($data, ‘certain word’)) { return “replacement line!\n”; } return $data; } $data = array_map(‘replace_a_line’, $data); file_put_contents(‘myfile’, $data); A quick note, PHP > 5.3.0 supports lambda functions … Read more
There are many different CoNLL formats since CoNLL is a different shared task each year. The format for CoNLL 2009 is described here. Each line represents a single word with a series of tab-separated fields. _s indicate empty values. Mate-Parser’s manual says that it uses the first 12 columns of CoNLL 2009: ID FORM LEMMA … Read more