[Scilab-users] csvread different separator exclusive)

scilab.20.browseruk at xoxy.net scilab.20.browseruk at xoxy.net
Tue May 24 09:45:56 CEST 2016


Florian,

If you have Perl available, you could regularise the file with the following one-liner:
 
perl -nle "print join ' ', split ' '" <in.file >out.file

(You'll need to switch 's to "s and vice versa if you're on *nix.)

(Despite the way that looks, the split ' ' will habdle any number of intervening spaces or tabs and join ' ', will replace them with a single space.
Use join "\t" to get a proper tab delimited output file.)

It takes around 30s/GB on my machine.

Cheers, Buk

> -----Original Message-----
> From: scilab.browseruk.c9f0207c9f.flotschos#gmail.com at ob.0sg.net
> Sent: Mon, 23 May 2016 23:15:20 +0200
> To: users at lists.scilab.org
> Subject: [Scilab-users] csvread different separator
> exclusive)
> 
> Hello
> I'm trying to write a function that reads data from a single file. It is
> a
> rather large file so I wanted to use the csvread function because it is
> faster than opening the file and then using scanf. The problem is, that
> my
> file is not a real csv file. It has different number of spaces in between
> every data entry.
> It looks like this:
> 
> 1 2  3   4   5 6 7   8
> the spaces between each entry is the same in every row so between 1 and 2
> there is a single space, between 2 and 3 there are two spaces, between
> 3-4
> and 4-5 three spaces, 5-6 one, 6-7 one and 7-8 three again.
> 
> 
> Is there a faster way than opening the file and using a scanf?
> 
> Thank you!
> Florian

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!






More information about the users mailing list