@Test public void testSedGrep() throws Exception { String[] directives = new String[] { "find-and-replace body s/\" }; List<Row> rows = Arrays.asList( new Row("body", "07/29/2013,Debt collection,\"Other (i.e. phone, health club, etc.)\",Cont'd attempts collect " + "debt not owed,Debt is not mine,,,\"NRA Group, LLC\",VA,20147,,N/A,Web,08/07/2013,Closed with non-monetary " + "relief,Yes,No,467801"), new Row("body", "07/29/2013,Mortgage,Conventional fixed mortgage,\"Loan servicing, payments, escrow account\",," + ",,Franklin Credit Management,CT,06106,,N/A,Web,07/30/2013,Closed with explanation,Yes,No,475823") ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 2); Assert.assertEquals("07/29/2013,Debt collection,Other (i.e. phone, health club, etc.),Cont'd " + "attempts collect debt not owed,Debt is not mine,,,NRA Group, LLC,VA,20147,,N/A," + "Web,08/07/2013,Closed with non-monetary relief,Yes,No,467801", rows.get(0).getValue("body")); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { for (String column : columns) { int idx = row.find(column); if (idx != -1) { Object v = row.getValue(idx); try { if (v instanceof String) { String value = (String) v; Unix4jCommandBuilder builder = Unix4j.echo(value).sed(pattern); if (builder.toExitValue() == 0) { row.setValue(idx, builder.toStringResult()); } } } catch (Exception e) { } } results.add(row); } } return results; }
FindAndReplace implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { for (String column : columns) { int idx = row.find(column); if (idx != -1) { Object v = row.getValue(idx); try { if (v instanceof String) { String value = (String) v; Unix4jCommandBuilder builder = Unix4j.echo(value).sed(pattern); if (builder.toExitValue() == 0) { row.setValue(idx, builder.toStringResult()); } } } catch (Exception e) { } } results.add(row); } } return results; } }
FindAndReplace implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { for (String column : columns) { int idx = row.find(column); if (idx != -1) { Object v = row.getValue(idx); try { if (v instanceof String) { String value = (String) v; Unix4jCommandBuilder builder = Unix4j.echo(value).sed(pattern); if (builder.toExitValue() == 0) { row.setValue(idx, builder.toStringResult()); } } } catch (Exception e) { } } results.add(row); } } return results; }  }
FindAndReplace implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { for (String column : columns) { int idx = row.find(column); if (idx != -1) { Object v = row.getValue(idx); try { if (v instanceof String) { String value = (String) v; Unix4jCommandBuilder builder = Unix4j.echo(value).sed(pattern); if (builder.toExitValue() == 0) { row.setValue(idx, builder.toStringResult()); } } } catch (Exception e) { } } results.add(row); } } return results; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); }
FindAndReplace implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { List<Row> results = new ArrayList<>(); for (Row row : rows) { for (String column : columns) { int idx = row.find(column); if (idx != -1) { Object v = row.getValue(idx); try { if (v instanceof String) { String value = (String) v; Unix4jCommandBuilder builder = Unix4j.echo(value).sed(pattern); if (builder.toExitValue() == 0) { row.setValue(idx, builder.toStringResult()); } } } catch (Exception e) { } } results.add(row); } } return results; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); static final String NAME; }