What will be the Regular Expression to parse give output - java

I want to extract the code count for the below command output. In the below example expected output is 286. What will be the regular expression to extract the code count?
Want to parse the below string in windows:
1 text file.
1 unique file.
0 files ignored.
http://cloc.sourceforge.net v 1.64 T=0.01 s (86.1 files/s, 1119.4 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C++ 1 0 0 13
-------------------------------------------------------------------------------

You can grep the last digits of a line by
grep -P "\d+$"

I can parse it in Linux using below:
grep -Eo '[0-9]+$'

Related

Get lines of code in src folder skipping comments and empty lines

Hi I already have something to get the lines of code but still it out puts the count having empty lines and comments counted.
git ls-files | grep "\.java$" | xargs wc -l
Can you modify this to skip comments and blank lines..?
Thanks in advance
Try CLOC, it can lists numbers in great detail.
You need to install CLOC first using syntax brew install cloc
cloc $(git ls-files)
Sample output for reference:
20 text files.
20 unique files.
6 files ignored.
http://cloc.sourceforge.net v 1.62 T=0.22 s (62.5 files/s, 2771.2 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Javascript 2 13 111 309
JSON 3 0 0 58
HTML 2 7 12 50
Handlebars 2 0 0 37
CoffeeScript 4 1 4 12
SASS 1 1 1 5
-------------------------------------------------------------------------------
SUM: 14 22 128 471
-------------------------------------------------------------------------------
Most test coverage tools also calculate LOC. For instance, Jacoco spits this out to Jenkins.

multiple delimeter and want to include that delimeter one of them in string using regex

i wanna ask something, this is my code
string.split("\\+|(?=-)|([=-]?=-)|=");
my input 2x^2+3x-9=-2
output :
2x^2 3x -9 2
my expected output :
2x^2 3x -9 -2
Place = alternative before [=-]?=-:
\+|=|(?=-)|([=-]?=-)
Demo: https://regex101.com/r/B7kE9R/1

Accessing multiple outputs of a Jar in a shell script

I am invoking a Jar(say abc.jar) which returns 3 outputs(which I have given as print statements in jar itself,say outputs from jar are
Emp name,Emp id and Email
and I was able to get these 3 outputs in the script in a single Variable which is not much of use.
I want to capture these outputs in 3 different variables to use them further.
Is there a way possible to store the different outputs of a jar into different variables in .sh?
details=$(java -jar /mydata/abc.jar)
echo $details
Output
Kevin 1234 abc#gmail.com
Yes, it's possible, you just need to evaluate the result and assign each value a variable.
$ details=$(java -jar /mydata/abc.jar)
$ r=`echo $details |gawk '{print "a="$1,"b="$2,"c="$3}'`
$ eval $r
# variable $a $b $c will store your value respectively
$ echo $a $b $c
Kevin 1234 abc#gmail.com

Sort records but keeping header at the top in Linux and Java

I need to sort records from a file by first column numerically but I need the header to stay at the top of the file.
I am using Java's Process Builder but I am not familiar with Linux commands so I am doing something wrong. This is what I need help with:
Process sort = new ProcessBuilder("/bin/bash", "-c", "((head -n -1 " +main_file+ " | tail -n -1) | sort -n) >> " + main_file).start();
You dont need java to execute a shell and perform the task, directly run the commands on shell .
See below
$ cat delitLater.txt
A 1
B 2
C 3
A 4
B 5
C 6
$ awk 'NR==1; NR > 1 {print $0 | "sort -n -k 1,1"}' delitLater.txt
A 1
A 4
B 2
B 5
C 3
C 6
$ awk 'NR==1; NR > 1 {print $0 | "sort -n -k 2,2"}' delitLater.txt
A 1
B 2
C 3
A 4
B 5
C 6
Using awk , you print the first line as is. This is done using NR(Rownumber) == 1 . For all other rows , you use the sort command and specify which columns to use . Sort key is defined by "-k" option . "-n" means numeric sort , but you might or might not need it depending upon the contents of your file.

BCP exits with code 0

When running BCP from my Java application it exits with status code 0 when 1 is expected.
I run bcp with an invalid combination of data and formatting file and bcp gives the following error:
Starting copy...
SQLState = 22005, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Invalid character value for cast specification
BCP copy in failed
BCP however exits with exit code 0 and not 1, as i suspect. Now it is extremely difficult to see if something failed while running BCP. Exitting with the right code works once they match to some degree (like same delimiters).
Command
PS C:\Users\feh\Desktop> bcp integrate_test.dbo.AS_LOADER_DELIMITED in .\data.dat -S "10.0.0.161\SQL2K5,1048" -U user -P pass -f .\formatting.ctl -m 1
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Unexpected EOF encountered in BCP data-file
0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 1
PS C:\Users\feh\Desktop> $lastexitcode
0
How can i validate a formatting file to the data and get a exit code 1 when they do not match?
If the bcp is "in" the consider using BULK INSERT. This does the same as bcp but can be trapped using SQL Server TRY/CATCH or normal exception handling
Otherwise, are you trapping %ERRORLEVEL% and not some other code?

Categories