Community Halloween is live until October 31st! Complete any 2 quick activities to earn the 2025 Community Halloween badge. Feeling brave? Check out the activities here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Help in Importing a batch txt file which inconsistent file format

sumaiyakhatun786
5 - Atom

Hello Team,

I want to import set of file from a folder, where every week new file is added . the format of the file is as attached . 

.tx batch file has junk or log info above, then multiple data blocks that all start with
|SGrp||Submission| (i.e., the header line). When I am trying to import the file and its coming in one column , but the header are splitting into two columns .  here row 13 and 14 both are headers.  Also the following rows the data inputs are spliting into two as well.

sumaiyakhatun786_0-1761133209300.png

I want to import those set of files where data points are aligned under each header and no logs or specials char. I have just stared using alteryx so have not faced this kind of file before, any help will be apppreciated.

 

8 REPLIES 8
SGolnik
11 - Bolide
11 - Bolide

I would start with one file and read the whole file in as a csv with \0 as the delimiter. This should put the whole file into a single cell. Parse to rows using text to columns on a new line delimiter \n. Filter out the garbage rows. Then parse to columns using the pipe delimiter. Once you have that file parsed out, then it can be turned into a batch macro.

 

https://knowledge.alteryx.com/index/s/article/Getting-Started-with-Batch-Macros-1583461640393 

https://help.alteryx.com/current/en/designer/apps-and-macros/macros/batch-macro.html 

davidskaife
14 - Magnetar

Hi @sumaiyakhatun786 

 

That was a fun challenge! Here is my take on it but its not dynamic so if the structure of the file (and any assumptions made on filtering etc) change it will break:

 

davidskaife_0-1761137006894.png

 

First import it in as a CSV with no delimiter, starting on row 13 and extend the Field Length so nothing gets missed:

 

davidskaife_1-1761137068699.png

 

You then want to filter out any rows that are not required, based on identified patterns:

 

davidskaife_2-1761137107325.png

 

Then you generate a row number, if it starts with a pipe then its 1, else its 2. Filter on row 1 and join these two streams back, but joining on record position:

 

davidskaife_3-1761137178497.png

 

Using Formula tool combine Field_1 and Right_Field_1, then using Text to Columns tool split on | into 66 columns (this is where it will break if the number of columns differ with each file).

 

Take the header from the first row of data using Dynamic Rename tool.

 

Remove any columns not required, undertake data cleansing to remove all the duplicate whitespace etc, and finally filter out any rows that start with SGrp to remove the extra headers.

 

I'd double check the output to make sure it aligns!

 

sumaiyakhatun786
5 - Atom

Hello davidskaife,

Thank you for the solution. Though it is not dynamic but solves 90% of the problem. I can work on making it dynamic, but your solutions helped with main problem. 

davidskaife
14 - Magnetar

Hi @sumaiyakhatun786 

 

You're very welcome. If you need help making it dynamic please do share the details and the Community can rise to the challenge!

 

As my workflow helped you would you mind accepting it as the solution so others may find and use it?

sumaiyakhatun786
5 - Atom

This is an accepted answer. Great help. I have a folder with muliple files as such , every week the folder is added new file. Here while importing I want to make the dynamic so that i do not need to mention the "Start data import on Line" as it might not be same for every file.

davidskaife
14 - Magnetar

Can you share the input file again?

sumaiyakhatun786
5 - Atom

I deleted some data inputs due to data security . But this is the  format.

davidskaife
14 - Magnetar

Hi @sumaiyakhatun786 

 

Thanks! I've updated the workflow - start importing on line 1, and have added additional filter clauses to the Filter tool to remove any of the preceding rows that are not required 

davidskaife_0-1761213079412.png

 

If other files have different data in the initial rows then you would need to add them in as a filter condition, so there is still an element of manual updating (if its needed).

 

If you want it truly dynamic i've also included another way, utilising macro's (second stream coming from the Input tool in the screenshot). What this essentially does is in the first macro it identifies the row number that the first instance of |SGrp appears, passes that to another macro which updates the 'Start Data Insert on Row' section, and then carries on as normal. 

 

davidskaife_1-1761214150607.png

 

Inside both macros (to open right click on them and select Open Macro) you will need to update the Macro Input and Input tools by pointing to your specific folder location, as they are pointing to my downloads folder. I've used a wildcard instead of the file name so it will pick up any text file in the folder you specify.

 

davidskaife_2-1761214682435.png

 

Hope this helps!

 

 

 

 

 

Labels
Top Solution Authors