cancel
Showing results for 
Search instead for 
Did you mean: 

To remove LF(line feeder) from last line in target file.

Former Member
0 Kudos

Hi PI Experts,

I am working on Receiver FCC, where i need to place a target file in an Unix server.

By default target file will get LF(line feeder) at the end of each line, but my requirement is not to populate LF for the last line.


Please find the below screen shot of sample target file


I have tried giving below shell commands in processing tab of communication channel


  1. sed -i '$s/..$//' file.txt
  2. sed '/^$/d'  file.txt
  3. $ sed 's/^ *//; s/ *$//; /^$/d; /^\s*$/d' file.txt > output.txt

   4.   sed '${/^$/d;}' file.txt

  3.    sed '/^\s*$/d' file.txt

but it is not working.

Please help me out.

Thanks in advance.

Thank you,

Chakradhar N

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Chakradhar,

1. Use StrictXml2PlainBean or MTB (remove FCC) in receiver channel.

2. After above module, add below custom adapter module to remove last byte (last new line character).


package com.test;

import java.util.Arrays;

import com.sap.aii.af.lib.mp.module.*;

import com.sap.engine.interfaces.messaging.api.*;

public class RemoveLastByte implements Module {

  @Override

  public ModuleData process(ModuleContext mc, ModuleData md) throws ModuleException {

  try {

  Message msg = (Message) md.getPrincipalData();

  Payload pay = msg.getMainPayload();

  java.io.InputStream in = pay.getInputStream();

  byte[] b = new byte[in.available()];

  in.read(b);

  // Remove last byte and write it to output.

  pay.setContent(Arrays.copyOf(b, b.length - 1));

  md.setPrincipalData(msg);

  } catch (Exception e) {

  throw new ModuleException(e);

  }

  return md;

  }

}

I have not tested above code (please use it as guide).

Former Member
0 Kudos

Hello Experts,

Is this behavior of adding an extra blank line at the end of file still present in PI 7.31?

And is the custom module creation the only option for it?

Regards,
Diptee

Answers (1)

Answers (1)

Harish
Active Contributor
0 Kudos

Hi,

refer the below thread

or you can try to give the hexadecimal value in the content conversion paramter.

0x0D     = Carriage return

0x0A     = NL line feed, new lineà

try the end saperator 0x0D.


regards,

Harish

Former Member
0 Kudos

Hi Mistri,

Thanks for quick reply

I have tried giving below for end separator but i am getting all the lines in a single line.

end separator  = 0x0D   (Carriage return)

end separator  = 0x0A    (NL line feed, new lineà)

end separator  = '' (null)

Also, i have checked below links and found that we don't have a conversion parameter to remove LF from the file.   I hope we have to do it by shell command/script.

http://wiki.scn.sap.com/wiki/download/attachments/37587/FCC_ramesh3.gif?original_fqdn=wiki.sdn.sap.c...

http://wiki.scn.sap.com/wiki/download/attachments/37587/FCC_ramesh5.gif?original_fqdn=wiki.sdn.sap.c...

http://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=40772

http://scn.sap.com/thread/1540983

Thank you,

Chakradhar N