Using the split function to parse a text file

added on December 19, 2011 by David Hubbard

The sample program writes out a table text file to be used as input. Normally this would be created using a text editor such as Wordpad or Textpad. Excel could be used for table-driven processing as well. Excel is more powerful and versatile while text is faster and uses less memory. The text file of parameters is read in and separated by the character '#'. In the example it just displays the table parameters as they are read, but in general the parameters would be used to perform some table-driven process. Each line is split into three words using the Split() function and puts each word into a separate variable.

Download This Task (2.4kb) Read Text and Split Line.aml
Would you like to upload a Sample Task or Workflow to the User Resource Center? Click here!

More Sample Tasks and Workflows

Dataset to CSV using ODS action 5/15/15Valentineo McGowan

How do I create a CSV file from a dataset without Microsoft Excel being present on my machine? Here's how to create a CSV file in one step using a dataset with our new 'ODS (OpenDocument Spreadsheet) - Set cells' activity.

Dataset to CSV File using Excel action 5/15/15Valentineo McGowan

How do I create a CSV file from a dataset without using Interactivity actions inside MS Excel, ie, 'File Save As.'? Here's how to create a CSV file in one step using a dataset with our 'Excel - Set cells' activity.

Count Rows in TXT/CSV using Regular Expression 5/15/15Valentineo McGowan

I have a *.txt or *.csv containing column headers and X rows of data. Using RegEx the task simply counts the number of rows based on carriage returns. Great for csv files that have X amount of records and you simply need a total count of rows minus the headers.

Split filename into two variables 5/15/15Valentineo McGowan

A task has a name of 'abc_123.txt' I would like the folder name to be the prefix of the filename prior to the "_" delimiter 'C:\abc'. File 123.txt will then be placed inside C:\abc\123.txt

Hide window 4/18/15Ali Zamani

Using this task, you can hide the windows that are active in the field of view. Posted by Younes Raeisi

Text Spinner/Randomizer aka Article Spinner 3/19/15Timur Khasanov

This task can be successfully applied in any area, be it SEO article writing, to make your content look as unique as possible every time you submit it, email marketing campaigns, to personalize your messages and adding authenticity in every message you send out, actually anything you can think of in Internet Marketing world and beyond! Input (at Step 11): put the words you want to randomly be chosen in brackets "{}", separated by "|" sign and that's it! Script automatically compiles a unique content every time you run it! Output is passed onto a variable and be used in further infrastructure. See for yourself.

AutoMate Holiday List 5/22/13Network Automation

This sample task will allow users to choose a holiday to search against, read the entire AutoMate holiday list, narrow the search by parameters for only United States holidays, and then find the date for the holiday selected.

SSH via email 5/22/13Brian Guy

run remote ssh commands via email

Terminal Emulation Task 3/3/13Network Automation

In this task, we will show you how AutoMate connects to a terminal server, logs in, changes the directory/folder, lists the files in the folder, extracts the content from the terminal window, loops through the content, and writes the lines containing the files listed to a text file.

Update a MySQL table from CSV files 12/5/12Jason Beckett

The scenario for this particular automate task was that we had text, CSV reports that we needed to import in to a MySQL database and needed to clear the particular table of all records before we started a new import. In order for this task to work we had to share the directory where the reports were at and need the task to loop through all of the files in the directory. The task steps are as follows: Create a variable named "var_FilePath" with an initial value of "\\\\\\sharename\\" (Notice the double backslash. It's a small nuance of MySQL that a backslash is a command character so you need a double backslash to represent a single backslash) Create a variable named "var_FullPath" Establish SQL Connection using... Here you use the built-in ODBC connection browser to connect to the MySQL database. IMPORTANT: You need to install the MySQL for Windows driver to be able to make this connection. You can get the driver at: Execute the SQL statement: "TRUNCATE TABLE tablename" Why use the TRUNCATE TABLE statement rather than UPDATE TABLE? There's a great debate in online forums about the merits of both but in this instance we wanted a clean table so the TRUNCATE statement was more efficient. Loop through files in directory "\\\sharename" Do not include the path in the variable. Create and populate dataset "ds_files" with details of the file(s). Set variable var_Fullpath to value "%var_Filepath & ds_Files.Name%" So what is this about? We need the MySQL statement to grab the files from the shared directory but we needed the value to be in the right format. So this step concatenates the variable var_FilePath and the file name of the report so that we get the final value of \\\\\\share\\report.csv Execute SQL statement: "LOAD DATA LOCAL INFILE '%var_FullPath%' INTO TABLE tablename COLUMNS TERMINATED BY '|' LINES TERMINATED BY '\n' IGNORE 1 LINES (COLUMN1,COLUMN2,COLUMN3);". End Loop Close SQL Connection


Leave a Comment

Please sign in to your account or your comment will be forever stored under "anonymous".
Include Code Snippet

Search the URC

Subscribe to Version History via RSS
Subscribe to Version History via RSS
Version Watcher

10.3.0 changelog
10.3.0 changelog
other versions downloads


Subscribe to Latest Resources via RSS
Subscribe to Latest Resources via RSS
Latest Resources

show filter options

Subscribe to Forum Posts via RSS
Subscribe to Forum Posts via RSS
Forum Posts