awk like sql

1)sample data

tk-no-MacBook-Pro:~ tk$ cat test.csv

01,8888888,9999999999

09,7777777,6666666666

02,2777333,9999992222

03,8888888,6567637476

2)select col2,col3 from ... where col1 = 09

tk-no-MacBook-Pro:~ tk$ awk -F, '{if ($1 == 09) print $2","$3;}' test.csv

7777777,6666666666

tk-no-MacBook-Pro:~ tk$ 

 

3)if you need format 

tk-no-MacBook-Pro:~ tk$ cat test.csv

01,8888888,9999999999

09,7777777,6666666666

02,2777333,9999992222

03,8888888,6567637476

09,667,8987233598

4)

tk-no-MacBook-Pro:~ tk$ awk -F, '{if ($1 == 09) printf "%07d%s%07d\n",$2,",",$3}' test.csv

7777777,6666666666

0000667,8987233598

how to grouping and maxBy (list of maps)

1) list of maps : 

f:id:annazola:20190701011158p:plain

sample list of maps

2) grouping and maxBy

 

f:id:annazola:20190701011524p:plain

main codes

3) before and results

 

f:id:annazola:20190701012001p:plain

 

 appendix) to copy

 

List<Optional<Map<String, Object>>>  aggrList = 

mockList.stream().collect(Collectors.groupingBy(p -> (String)p.get("niveau_1")+ (String)p.get("niveau_2")+(String)p.get("franchise"),

Collectors.maxBy(Comparator.comparingLong(p->Long.valueOf(p.get("cnt").toString())))))

.values().stream().collect(Collectors.toList());

 

List<Map<String, Object>>  endList= new ArrayList<>();

aggrList.stream().forEach(s->{

endList.add(s.get());

});

System.out.println("result list");

endList.stream().forEach(System.out::println);

 

 

spring batch : junit test sample

1.project files are below(use terasolua spring batch sample)

f:id:annazola:20190513073109p:plain

2.test codes(test class)

package batch;

 

 

import static org.junit.Assert.fail;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.junit.runners.JUnit4;

import org.springframework.batch.core.JobParameters;

import org.springframework.batch.test.JobLauncherTestUtils;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

 

 

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = { "classpath:test-context.xml" ,

"classpath:job01.xml"})

 

public class testJob01 {

 

@Autowired

    private JobLauncherTestUtils jobLauncherTestUtils;

 

@Test

    public void testJob() throws Exception {

jobLauncherTestUtils.launchJob();

    }

 

}

 *if you code "JUnit4.class" after @RunWith annotation, @Autowired

failed(NPE)

 

3.test codes(setting file: test-context.xml)

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:p="http://www.springframework.org/schema/p"

       xmlns:batch="http://www.springframework.org/schema/batch"

       xmlns:util="http://www.springframework.org/schema/util"

       xmlns:jdbc="http://www.springframework.org/schema/jdbc"

       xmlns:c="http://www.springframework.org/schema/c"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

            http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd

            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd

            http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">

 

    <bean id="jobLauncherTestUtils" class="org.springframework.batch.test.JobLauncherTestUtils">

        <property name="job" ref="job01" />

        <property name="jobRepository" ref="jobRepository" />

        <property name="jobLauncher" ref="jobLauncher" />

    </bean>

    </beans>

ls with timestamp (BSD ver.)

ls -l below

tk-no-MacBook-Pro:webapps tk$ ls -l

total 51584

drwxr-xr-x@ 10 tk  staff       340  1 29  2008 ROOT

drwxr-xr-x@  5 tk  staff       170  1 29  2008 balancer

drwxr-xr-x@ 23 tk  staff       782  1 29  2008 jsp-examples

drwxr-xr-x@ 11 tk  staff       374  1 29  2008 servlets-examples

drwxr-xr-x@ 44 tk  staff      1496  1 29  2008 tomcat-docs

drwxr-xr-x  24 tk  staff       816  3 11 22:16 tutorial-thin

-rw-r--r--   1 tk  staff  14953152  3 10 03:22 tutorial-thin.tar.gz

-rw-r--r--   1 tk  staff  11455414  3 10 22:42 tutorial-thin.war

drwxr-xr-x@  6 tk  staff       204  1 29  2008 webdav

this year : with time detail

last year : no time detail

try to ls -full--time

tk-no-MacBook-Pro:webapps tk$ ls --full-time

ls: illegal option -- -

usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

BSD ver "ls" command cant use option "--full-time"

should use "Tl" 

tk-no-MacBook-Pro:webapps tk$ ls -Tl

total 51584

drwxr-xr-x@ 10 tk  staff       340  1 29 05:38:54 2008 ROOT

drwxr-xr-x@  5 tk  staff       170  1 29 05:38:54 2008 balancer

drwxr-xr-x@ 23 tk  staff       782  1 29 05:38:53 2008 jsp-examples

drwxr-xr-x@ 11 tk  staff       374  1 29 05:38:54 2008 servlets-examples

drwxr-xr-x@ 44 tk  staff      1496  1 29 05:38:58 2008 tomcat-docs

drwxr-xr-x  24 tk  staff       816  3 11 22:16:56 2019 tutorial-thin

-rw-r--r--   1 tk  staff  14953152  3 10 03:22:54 2019 tutorial-thin.tar.gz

-rw-r--r--   1 tk  staff  11455414  3 10 22:42:33 2019 tutorial-thin.war

drwxr-xr-x@  6 tk  staff       204  1 29 05:38:54 2008 webdav