read each line in from a file

Post any question you may have in regards to GoAnywhere MFT and let our talented support staff and other users assist you.
2 posts Page 1 of 1

jmartin

Posts: 1
Joined: Wed Nov 11, 2015 8:15 pm

Post by jmartin » Fri Dec 15, 2017 7:45 pm
read each line in a file

I am trying to read in each line in a generated file but having difficulty.
The file is created in the workspace via the Native Command, its just a 'ls -1' on a directory.

The results look like below in a file called ls1output.txt in the workspace.
svt-acro
svt-aeroman
svt-aim
svt-anz


I set my rowset variable to: ls1rowSet
and then do a foreach loop to print the lines.

which results in:
12/15/17 4:41:31 PM INFO Executing task 'readFlatFile 1.0'
12/15/17 4:41:31 PM INFO Data parsed successfully and the rowset variable 'ls1rowSet' was created
12/15/17 4:41:31 PM INFO Finished task 'readFlatFile 1.0'
12/15/17 4:41:31 PM INFO Entering loop 'forEachLoop'
12/15/17 4:41:31 PM INFO Opening file '/usr/local/Linoma_Software/GoAnywhere/userdata/workspace/1000000034569/ls1output.txt'
12/15/17 4:41:31 PM INFO Executing task 'print 1.0'
12/15/17 4:41:31 PM INFO com.linoma.ga.projects.tasks.converters.flatfile.FlatFileRowSet@318ee04d

How can I read these lines in 1 by 1?

Any help is appreciated, tia.

<project name="Seat Vendor Transfers" mainModule="Main" version="2.0" logLevel="debug">
<description>Seat Vendor Testing upload to LAMP</description>

<module name="Main">

<createWorkspace version="1.0" />


<callModule label="Call: Native Cmd" module="Native Cmd" version="1.0" disabled="false" />
<callModule label="Call DirList" module="Create DirList" version="1.0" disabled="true" />
<callModule module="Files" version="1.0" />
<deleteWorkspace version="1.0" disabled="true" />
</module>


<module name="Native Cmd" description="runs ls -1 on dir, outputs to file">

<exec executable="ls" executableDir="/usr/bin/" workingDir="/usr/local/Linoma_Software/home/SVT" redirectOutputTo="file" outputFile="./ls1output.txt" outputFileVariable="ls1varout" version="1.0">
<arg value="-1" />
<arg value="/usr/local/Linoma_Software/home/SVT" />
</exec>

</module>


<module name="Files">

<readFlatFile inputFile="./ls1output.txt" outputRowSetVariable="ls1rowSet" version="1.0" />

<forEachLoop itemsVariable="${ls1rowSet}" currentItemVariable="currItem">

<print version="1.0">
<![CDATA[${currItem}]]>
</print>

</forEachLoop>
</module>


<module name="Create DirList">

<createFileList fileListVariable="dirList" version="1.0">
<fileset dir="${ls1varout}" />
</createFileList>

</module>

</project>

Support_Josh

User avatar
Posts: 12
Joined: Thu Feb 16, 2017 11:20 am

Post by Support_Josh » Wed Jan 03, 2018 12:03 pm
The issue that you are running into is a difference between what GoAnywhere MFT is expecting as a Record Delimiter and what the file actually is. If the file was created on a Linux OS, the EOL characters only consist of LF characters but MFT is set to look for CRLF to separate each record. Since the file doesn’t have those line endings, GoAnywhere MFT will read in the entire file as a single line.

To change that behavior, navigate to the Read Flat File task and open up the Advanced tab. Once opened up, you need to switch your Record Delimiter from CRLF to just LF. See screenshot below:
42LaA9a.png
After making that change, your records should parse out separately and then should be able to create file lists as expected!
Joshua Przybysz
Senior Support Analyst
e. goanywhere.support@helpsystems.com
p. 1.800.949.4696
w. HelpSystems.com
2 posts Page 1 of 1