Can I change the headings in a .csv file?
Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
3 posts
Page 1 of 1
Is it possible to change a header record or write a header record to a csv file?
I have a csv file that has a header record. I'd like to keep the header record, but I need to change a few of the headings. For example, the header consists of "FileId", "NumSequence","Description1","Description2", and I'd like to change the header to be "File Id","Seq No.","Desc1","Desc2".
I have a csv file that has a header record. I'd like to keep the header record, but I need to change a few of the headings. For example, the header consists of "FileId", "NumSequence","Description1","Description2", and I'd like to change the header to be "File Id","Seq No.","Desc1","Desc2".
- Support Specialist
- Posts: 590
- Joined: Tue Jul 17, 2012 2:12 pm
- Location: Phoenix, AZ
-
If you are creating the CSV file from your data, you could select this header information from an SQL Select statement and write out the header row to a Temp file, then append your matching CSV data to that file.
You could also just "print" the header row into the file, then append your matching CSV data to that file as well.
In pseudo terms ...
Select "File Id","Seq No.","Desc1","Desc2" from SomeTable --> Header (RowSet Variable)
Select FileID, SeqNo, Desc1, Desc2 from SomeTable --> Detail (RowSet Variable)
WriteCSV using ${Header} --> MyCSVFile.csv (append = false)
WriteCSV using ${Detail} --> MyCSVFile.csv (append = true)
Not knowing how you're generating the data to create the CSV file, these are a few options to doing just that.
You could also just "print" the header row into the file, then append your matching CSV data to that file as well.
In pseudo terms ...
Select "File Id","Seq No.","Desc1","Desc2" from SomeTable --> Header (RowSet Variable)
Select FileID, SeqNo, Desc1, Desc2 from SomeTable --> Detail (RowSet Variable)
WriteCSV using ${Header} --> MyCSVFile.csv (append = false)
WriteCSV using ${Detail} --> MyCSVFile.csv (append = true)
Not knowing how you're generating the data to create the CSV file, these are a few options to doing just that.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
Thank you for the reply Rick! The csv file I am working with is coming from an external system that I am retrieving via sftp. Once I have the file, then I need to change the headings. Do I need to create a csv file from scratch that would contain only the headings I need before I bring in the csv file from outside? If so, how do I create such a csv file from within the project? I've included what code I have at this point. Any further suggestions? Thank you!
Code: Select all
<project name="test_changing_header" mainModule="Main" version="2.0" logLevel="debug">
<module name="Main">
<createWorkspace label="Create Workspace" version="1.0" logLevel="debug" />
<sftp label="sftp - sftp connection to test server" resourceId="test1-sftp" outputSessionId="test1ID" version="1.0" logLevel="debug">
<get label="get - get Test file from server" destinationDir="${system.job.workspace}" suffix="-${CurrentTimestamp('yyyyMMddhhmmss')}" destinationFilesVariable="LocFiles" numFilesDownloadedVariable="FileDwnldCount" processedSourceFilesVariable="RemoteFiles">
<fileset dir="/tst/test/incoming">
<regexFilter>
<include pattern="^TST - TestFile [0-9]{8} [0-9]{6} [0-9]{1}.csv\Z" caseSensitive="false" />
</regexFilter>
</fileset>
</get>
</sftp>
<readCSV inputFilesVariable="${LocFiles}" outputRowSetVariable="data" skipFirstRow="true" version="1.0" disabled="false">
<data>
<column index="1" name="File Id" size="4" />
<column index="2" name="Seq Number" size="2" />
<column index="3" name="Description1" size="25" />
<column index="4" name="Description2" size="13" />
</data>
</readCSV>
<writeCSV inputRowSetVariable="${data}" outputFile="${system.job.workspace}\temp_TestFile_${CurrentTimestamp('yyyyMMddhhmmss')}.csv" includeHeadings="false" outputFileVariable="outFile" version="1.0" disabled="false" />
</module>
</project>
3 posts
Page 1 of 1