[Date Index] [Thread Index] [Author Index]
Re: importing fixed width data
swiftset wrote: > Hi, I'm trying to import data from a file where the fields are stored > in a fixed width format. The Import["file", "Table"] command is the > closest I can get to what I'd like, but then the data is divided using > whitespace, so I get a lot of extraneous fields, and no way to tell > whether what Mathematica imported as two fields is actually just one > that contained a whitespace. > One possibility is to convert the file to a format that uses a comma as the delimiter (if your data has no commas in it), and then import as Import["file", "CSV"] The 'cut' command line program can do the conversion, and it can be used directly from Mathematica (if you have already have it installed and it's in the path). Here's an example: Import["!cut -c1-5,6-13,14- --output-delimiter=, file", "CSV"] The -c1-5,6-13,14- part specifies the character ranges that should be taken as separate fields.