c# - Count lines for a particular string combination -
i trying count no. of lines in productservices , add product appearing.
logs :
info [productservices] add product has been performed gulanand on product id 424 () info [productservices] add product has been performed gulanand on product id 424 () info [productservices] add product has been performed gulanand on product id 424 () info [productservices] update product has been performed gulanand on product id 424 () info [productservices] update product has been performed gulanand on product id 424 () info [productservices] add product has been performed gulanand on product id 424 () info [productservices] add product has been performed gulanand on product id 424 () info [productservices] add product has been performed gulanand on product id 424 ()
code have tried :
ienumerable<string> textlines = directory.getfiles(@"c:\users\karansha\desktop\ashish logs\", "*.*") .select(filepath => file.readalllines(filepath)) .selectmany(line => line); list<string> users = new list<string>(); regex r = new regex(@"*productservices\sadd product"); foreach (string line in textlines) { if (r.ismatch(line)) { users.add(line); } } //string[] textlines1 = new list<string>(users).toarray(); int countlines = users.count(); console.writeline("productscreated=" + countlines);
what this: (for each file)
string[] lines = file.readalllines(filepath) int count = lines.count(input => input.contains("productservices") && input.contains("add product"));
Comments
Post a Comment