Number of lines in Parsed file by PMD - pmd

I am using PMD for the first time. So I am not very sure about all the usage of it.
My goal is to find the total number of lines in all the files which are parsed by PMD.
Is there any way I can achieve that?

Related

How to generate a 10000 lines test file from original file with 10 lines?

I want to test an application with a file containing 10000 lines of records (plus header and footer lines). I have a test file with 10 lines now, so I want to duplicate these line 1000 times. I don't want to create a C# code in my app to generate that file (is only for test), so I am looking for a different and simple way to do that.
What kind of tool can I use to do that? CMD? Visual Studio/VS Code extension? Any thought?
If your data is textual, load the 10 records from your test file into an editor. Select all, copy, insert at the end of file. Repeat until the file is of length 10000+
This procedure requires ceil(log_2(1000)) cycles, 10 in your case, in general ceil(log_2(<target_number_of_lines>/<base_number_of_lines>)).
Alternative (large files)
Modern editors should not have performance problems here. However, the principle can be applied using a cat cli command. Assuming that you copy the original file into a file named dup0.txt proceed as follows:
cat dup0.txt dup0.txt >dup1.txt
cat dup1.txt dup1.txt >dup0.txt
leaving you with the quadrupled number of lines in dup0.txt.

read a formula stored in a text file in scalding

The problem is that i have 2 files :
1st file having 4 columns as in
1,Sanchit,60,80
2nd file having 2 columns as in
1,(1-(x/y))>1
now i want to apply the formula in 2nd file on values 60 and 80 which i will read from 1st file.
I have tried reading the formula column and wish to compute the formula using the mentioned values, but unable to do so.
Any kind of help will be appreciated. thanx
EDIT : There is a java api that helps. I have included that into my project and now works great
Evaluating a math expression given in string form
Head over to this link for the solutions
Strictly speaking, this is not exacly a Scalding question but you can use something like Apache Commons JeXL to execute formulas dynamically. So you would read the formula from the 2nd file, give it first file record object as a context and execute it.

diff ignore certain pattern in the file

I want to make diff between two files which contains lines beginning with "line_$NR". I want to make diff between the files making abstraction of the presence of "lines_$NR" but when the differences are printed I want lines_$NR to be displayed.
It is possible to do that?
Thanks.
I believe in this case, you have to preprocess your iput files to remove /^line_[0-9]*/, diff the resulting files, then recombine the diff output with the removed words according to line numbers in diff output.
Python's difflib should be very handy here, or same from perl. If you want to stick to shell, I suppose you could get by with awk.
If you don't need exact output, perhaps you can use diff's --line-format=... directive to inject actual line number in a diff, rather than the word you removed in preprocessing step.

Paginate a big text file

I have a big text file. Each line in the file is a record. And I need to parse the text file and show only 20 records in a HTML table at a time. I will have to support sorting as well.
What I am currently doing is read the file line by line based on the parameters start, stop, and page_size which is provided in querystring. It seems to work fine until I have to sort the records, because in order to sort I need to process every line in the text file.
So is there a Unix command which can I extract from line to line and sort? I tried grep but I do not know enough it to get this problem solved.
Take a look at the pr command. This is what we use to use all the time to paginate big files. You can set the page length, headers, footers, turn on line numbers, etc.
There's probably even a way to munge the output into HTML.
How big is the file?
man sort
Here

Find number of lines in a project in eclipse?

Is there a pluging/feature to count the number of lines in a project?
This may be what you're looking for: http://metrics2.sourceforge.net/
A very simplistic way is to do a regular expression search for '\n' in your project. It will give you a good idea on the number of lines in your project without installing any extra plug-ins.
Instead of installing a new eclipse plugin; If you are on a linux system:
cd to the eclispe project source directory(workspace/project-name/src)
and enter in termianl:
wc -l *.java
This will show you total number of lines as well as number of lines in each file
A quick way to do it is based on this tutorial I found: http://stephendnicholas.com/posts/eclipse-quick-line-count
To summarize, do the following (to use search in Eclipse press Ctrl+H):
Find the total amount of lines: Search your code for \n using 'regular expression' under your code files (e.g. if you develop in java only then search only *.java files).
Find the total amount of blank lines: Search your code for ^\s*\n
Find the total amount of commented lines: search your code for //.*(\n{1})?
Finally: Get the total amount of lines of code by subtracting 2 and 3 from 1.