How to "read in" a tab delimited file

Discussion created by Mitch_Denis_38 on Sep 17, 2014
Latest reply on Sep 19, 2014 by Pete Wirfs
Another question came up this week in Support regarding reading through a tab delimited file and checking one of the columns in the file for information.  I figured that we could throw this out there as a how to so the whole community can benefit.

This will loop through the lines in a text file on an agent and split each line into columns that are split by "tab" characters.  In this case, my file had three columns in it.  A big part of this is knowing how many columns you have so that you can correctly use them.  I then print out each column and have added in a line counter so we can see which line of the file is looked at.
!get line count :set &line_count# = 0 !loop through text file on host, making each column tab delimited :set &hnd# = prep_process_file('vwaswv9u01_os_01', 'C:\temp\tab_delimited_file.txt',,'COL=DELIMITER','DELIMITER=<TAB>') :process &hnd# !  increase line count and remove leading zeroes :  set &line_count# = add(&line_count#, 1) :  set &line_count# = format(&line_count#) !  get column 1 :  set &c1# = get_process_line(&hnd#, 1) !  get column 2 :  set &c2# = get_process_line(&hnd#, 2) !  get column 3 :  set &c3# = get_process_line(&hnd#, 3) !  print columns :  p 'Line &line_count# column 1 is "&c1#"' :  p 'Line &line_count# column 2 is "&c2#"' :  p 'Line &line_count# column 3 is "&c3#"' :endprocess

The main parts that allow us to split up each line into different columns is the 'COL=DELIMITER','DELIMITER=<TAB>' part.  There's a lot of other cool things you can do with this - you can read in just lines with certain strings in them by adding in a search in the parameter after the file name:

!loop through text file on host, find each line with "Mitch" in it, and make each column tab delimited :set &hnd# = prep_process_file('vwaswv9u01_os_01', 'C:\temp\tab_delimited_file.txt',"*Mitch*,'COL=DELIMITER','DELIMITER=<TAB>')

Here is the documentation forPREP_PROCESS_FILE and forGET_PROCESS_LINE.

What do you all do with PREP_PROCESS_FILE?  Anything cool?