One Star

[resolved] how to remove fisrt and last line from a text field ?

Hello,
I'am trying to remove the first line and the last line from a text field.
This can be done with tFileInputDelimited by setting header and footer parameter but this doesn't sound as the good solution.

could you help me ?
k.regards
Nicolas
9 REPLIES
Community Manager

Re: [resolved] how to remove fisrt and last line from a text field ?

Hello
Using the tFileInputFullRow with setting header and footer.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] how to remove fisrt and last line from a text field ?

Thanks ! I'll try it now.
k.regards
Four Stars

Re: [resolved] how to remove fisrt and last line from a text field ?

I have a input text file with some text inside it. I want to delete the first two lines and get the same output. I want to do it for a set of files automatically rather manually.
See my sample i/o attached.
 in the input two lines are blank before the text.
I want the Output after removing the first two blank lines.
Note: It's a text file with loat of paragraphs, can't denote them in rows/columns
The input, output(desired) files are attached
Kindly advice.
Community Manager

Re: [resolved] how to remove fisrt and last line from a text field ?

Hi tvsr984
If all these files are in the same folder, you can use tFileList to iterate all the files, use tFileInputFullRow to read each file line by line and set the header as 2 to split the first two rows, write the lines to a new file. For example:
tFileList--iterate--tFileinputFullRow--main--tFileOutputDelimited.  
on tFileINputFullRow: set the file path as:
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))
on tFileOutputDelimited: set the file path as:
"yourFolder/"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: [resolved] how to remove fisrt and last line from a text field ?

Thanks Hong for the timely rely.
I did the exact same what you described. But the issue is the output file has extra line spaces and the tab space comes in before every line the line seperator is \n and filed seperator is " ".
Any idea what might be the issue?
Thanks
Community Manager

Re: [resolved] how to remove fisrt and last line from a text field ?

The line read from the source file, I don't understand why the output file has extra line spaces. Can you show me an example file?
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: [resolved] how to remove fisrt and last line from a text field ?

Thanks hong. I found the issue. I just put in the line seperator as "\r\n" at the ouput end instead of "\n" alone. That does the magic!!. Thanks a lot for your support in the needy time.
One Star

Re: [resolved] how to remove fisrt and last line from a text field ?

Hi All,
I have 2 fixed length text files with below mentioned contents -
Main Header
Sub-Header-1
Row-1
""
Row-10
Sub-Footer-1
Sub-Header-2
Row-1
"
Row-10
Sub-Footer-2
Main Footer
Now i need a same Fixed length text file with following output -
Main Header
Sub-Header-1
Row-1
""
Row-10
Sub-Footer-1
Sub-Header-2
Row-1
"
Row-10
Sub-Footer-2
Sub-Header-3
Row-1
""
Row-10
Sub-Footer-3
Sub-Header-4
Row-1
"
Row-10
Sub-Footer-4
Main Footer
What approach I have to follow here ?
Ten Stars

Re: [resolved] how to remove fisrt and last line from a text field ?

If all you're doing is combining the files without needing to transform anything, you can read in file1 stripping the main footer and write to a new output file, then read in file2 stripping the main header and append to the same output file.