line-count

Is there a way in Matlab to determine the number of lines in a file without looping through each line?

我与影子孤独终老i 提交于 2020-01-09 06:20:55
问题 Obviously one could loop through a file using fgetl or similar function and increment a counter, but is there a way to determine the number of lines in a file without doing such a loop? 回答1: I like to use the following code for exactly this task fid = fopen('someTextFile.txt', 'rb'); %# Get file size. fseek(fid, 0, 'eof'); fileSize = ftell(fid); frewind(fid); %# Read the whole file. data = fread(fid, fileSize, 'uint8'); %# Count number of line-feeds and increase by one. numLines = sum(data ==

How to compare number of lines of two files using Awk

≯℡__Kan透↙ 提交于 2019-12-25 04:44:13
问题 I am new to awk and need to compare the number of lines of two files. The script shall return true, if lines(f1) == (lines(f2)+1) otherwise false. How can I do that? Best regards 回答1: If it has to be awk : awk 'NR==FNR{x++} END{ if(x!=FNR){exit 1} }' file1 file2 The varibale x is incremented and contains the number of line of file1 and FNR contains the number of file2 . At the end, both are compared and the script is exited 0 or 1. See an example: user@host:~$ awk 'NR==FNR{x++} END{ if(x!=FNR

Android Edittext: Get LineCount in an Activity's onCreate()

痴心易碎 提交于 2019-12-24 01:25:17
问题 How can I do getLineCount() of an Edittext in the onCreate() method of an activity, having changed the Edittext's text, like the following: @override public void onCreate(Bundle savedInstanceState){ myEditText.setText("EXAMPLE"); myEditText.getLineCount(); } Because the view has not been drawn yet getLineCount() will always return 0. Is there a way to get around this problem? Thanks! 回答1: Ugh, it's a problem with UI everywhere. You can use a Handler. You'll post a Runnable that will get the

GIT contribution per author (lines)

北慕城南 提交于 2019-12-18 13:23:10
问题 I'm trying to print the per-line contribution of each author to a Git repository. For that, I use the following command, adapted from How to count total lines changed by a specific author in a Git repository? git ls-tree -r -z --name-only HEAD -- */*.c | xargs -0 -n1 git blame \ --line-porcelain HEAD |grep "^author "|sort|uniq -c|sort -nr However, I get the following error: fatal: cannot stat path 'HEAD': No such file or directory. What am I doing wrong? 回答1: Okay, after more investigation I

How do you count the lines of code in a Visual Studio solution?

故事扮演 提交于 2019-12-17 02:53:30
问题 Is it possible to find the number of lines of code in an entire solution? I've heard of MZ-Tools, but is there an open source equivalent? 回答1: Visual Studio 2010 Ultimate has this built-in. Analyze -> Calculate Code Metrics 回答2: I've found powershell useful for this. I consider LoC to be a pretty bogus metric anyway, so I don't believe anything more formal should be required. From a smallish solution's directory: PS C:\Path> (gci -include *.cs,*.xaml -recurse | select-string .).Count 8396 PS

Line counting and abberant results

人走茶凉 提交于 2019-12-13 00:18:23
问题 I'm writing a utility to count the lines in a given file via the Unix command line. Normally this would be dead simple for me, but apparently I'm having a major off night. The goal of this program is to take in an unknown number of files from the command line, read them into a buffer and check for the newline character. Sounds simple? int size= 4096; int main(int argc, char *argv[]){ int fd, i, j, c, fileLines, totalLines; char *buf= (char *)malloc(size); //read buffer for (i=2; i<argc; i++){

UITextView count lines not working as intended

送分小仙女□ 提交于 2019-12-12 06:38:06
问题 I'm trying to get the amount of lines in a TextView . I've searched here for a solution, basically every thread has the same answer : contentheight/fontlineheight. I have a TextView with 8 lines, i run this code and i get contsize : 1.944413 NSLog(@"contsize : %f", descLabel.contentSize.height/descLabel.font.lineHeight); What am i doing wrong? 回答1: For iOS7, a version that take care that you can have differents font (and font size) in your UITextView : - (NSUInteger)numberOfLinesInTextView:

RTF Line count in Java

元气小坏坏 提交于 2019-12-11 13:29:33
问题 Kindly let me know any API to calculate the line count for RTF document. Apache POI or Aspose works for document, but its not able to find line count for RTF. Thanks. 回答1: Java already has a built-in RTF-Parser: RTFEditorKit. Take a look at its read method. For example: test.rtf file contents hello stackoverflow users So, it has 3 lines separated by \n . Code: FileInputStream stream = new FileInputStream("test.rtf"); RTFEditorKit kit = new RTFEditorKit(); Document doc = kit

API for simple File (line count) functions in Java

眉间皱痕 提交于 2019-12-09 00:54:32
问题 Hi : Given an arbitrary file (java), I want to count the lines. This is easy enough, for example, using Apache's FileUtils.readLines(...) method... However, for large files, reading a whole file in place is ludicrous (i.e. just to count lines). One home-grown option : Create BufferedReader or use the FileUtils.lineIterator function, and count the lines. However, I'm assuming there could be a (low memory), up to date API for doing simple large File operations with a minimal amount of boiler

D2010 compiled line count discrepancy

二次信任 提交于 2019-12-06 19:47:47
问题 When building a project there are two places where source line count is reported: On the compile progress dialog Under Project | Information In Delphi 2007 these two numbers were identical for the project we are building. In Delphi 2010 these two numbers are wildly different. The (1st) count is larger by a count of 1 million lines or 40%. The (2nd) count is close enough to the Delphi 2007 count to be satisfied the correct files are being built accounting for code changes in porting to D2010.