Results 1 to 4 of 4
I have a text file, which contains two columns of data - I've also split it with cut, so I could just as easily work from two files, each with ...
- 01-27-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 5
Creating a CSV file from columns in text file
I have a text file, which contains two columns of data - I've also split it with cut, so I could just as easily work from two files, each with one column.
I need to combine them to form a CSV file, currently I'm doing it thus:
You can see I'm also using tr to do some work. The problem is this script has to run on cygwin, and cygwin is very slow at loading programs. Each call to tr and cut takes ages, so this loop, operating on files of hundreds or thousands of lines, takes a very long time. What I need to try to do, is find a way to achieve the same result, without using a loop.Code:while read line; do echo $line | cut -c 1-5 | tr -d '\000''\004''\012' >> data.csv echo -ne "," >> data.csv echo $line | cut -c 7-12 | tr -d '\000''\004''\012' >> data.csv echo -ne "\n" >> data.csv done </tmp/data
Is there any way to do this without looping?
- 01-28-2011 #2
Loading the initial file in OpenOffice or LibreOffice calc, and saving as .csv, should do it easily. Reinventing the wheel is not a productive exercise.
- 01-28-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 5
High volume data coming from a spectrometer. But never mind, the solution is to use sed,and regular expressions to take care of things.
Thanks anyway.
- 01-28-2011 #4
Ah, that makes a difference. Yes, sed is probably the tool of choice for streaming data.


Reply With Quote