Ask Your Question
1

remove character in jython [closed]

asked 2019-07-23 09:33:29 -0500

Vss@2019 gravatar image

updated 2019-07-23 09:47:30 -0500

How to remove last delimiter from each file using jython evaluator if there is no data beyond that. There is one special character in last row. It has to remain same.

My input looks like

no;name;address; 
1;aaa;xyz;
2;bbb;abc;
3;ccc;ddd
4;eee;fff;
5;gíg;hhh;

Expected output should looks like.. 4th row remains same it doesn't contain anything which we are looking for delimiter.

no;name;address 
1;aaa;xyz
2;bbb;abc
3;ccc;ddd
4;eee;fff
5;gíg;hhh;
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Vss@2019
close date 2019-07-26 22:17:31.779948

2 Answers

Sort by » oldest newest most voted
0

answered 2019-07-23 12:17:29 -0500

Vss@2019 gravatar image

Thank you metadaddy..my scenario is whole file as target stage and creating event from that i want to read data. not sure your solution works

edit flag offensive delete link more
1

answered 2019-07-23 09:46:31 -0500

metadaddy gravatar image

updated 2019-07-23 12:12:04 -0500

DELIMITER = ';'

for record in records:
  try:
    # Assuming the data is in the /text field
    if record.value['text'].endswith(DELIMITER):
      record.value['text'] = record.value['text'][:-1]

    output.write(record)

  except Exception as e:
    # Send record to error
    error.write(record, str(e))

image description

edit flag offensive delete link more

Comments

@metadaddy : I want to read it from file and load it into different file using jython. Is this possible to do it in Jython evaluator instead of target stages. It can be multiple files in the same directory

Vss@2019 gravatar imageVss@2019 ( 2019-07-23 09:50:09 -0500 )edit

I would use the Directory origin and Local FS destination. If you're doing it all in Jython, you might as well just write a Python script and run it from the command line.

metadaddy gravatar imagemetadaddy ( 2019-07-23 10:23:22 -0500 )edit

How to read whole record in if statement if we are reading from directory origin ?

Vss@2019 gravatar imageVss@2019 ( 2019-07-23 10:39:48 -0500 )edit

You can use the Text data format and it will put the entire line in the /text field.

metadaddy gravatar imagemetadaddy ( 2019-07-23 12:11:32 -0500 )edit

I'm not sure what your use case looks like. The Slack channel or Google Group might be a better place to discuss this - see https://streamsets.com/community

metadaddy gravatar imagemetadaddy ( 2019-07-23 18:08:41 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-23 09:33:29 -0500

Seen: 62 times

Last updated: Jul 23