Jump to content

Recommended Posts

Hello there! a newbie here, just want to ask how to create a function that can read a multiple text file (searching specific text or group of strings) and then convert this into a table. 

Sample

Filename | Search String1 | Search String2 | Search String3 |

Link to comment
Share on other sites

Hi John,

One of my customers used this TERR script to load multiple files located in a specific folder. You may give it a try and see if it works out for you as well.

#Name your path

mypath <- "//Documents/Departments$/ABC/Spotfire/Spotfire Data/"

#Find all files in the folder which match the pattern

files <- list.files(path = mypath,pattern = "*.txt")

options(warn=-1)

# Create an empty data frame which will be your end result

combined <- data.frame()

#Loop through all files, read them and append them (via a rbind = row bind) to your result data frame

for(file in 1:length(files))

{   df <- read.table(paste(path,files[file],sep=""),header=T,sep=';')   combined <- rbind(combined,df) }

 

Kind regards,

David

Link to comment
Share on other sites

Any idea how to search specific strings inside a multiple text file and then convert this into a table??

File name | String 1 | String 2 | String 3 | String 4

A.txt          | A.1         |  A.2        | A.3          | A.4

B.txt          | B.1         | B.2          | B.3          | B.4 

Link to comment
Share on other sites

Hi John,

For better visibility of new requests, could you create a new question for the search string one? And maybe elaborate a bit more? Do you want to search within  .txt files or are the files already imported into Spotfire and then do a search (and convert to a table)?

Kind regards,

David

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...