Parsing text file

I’m looking at parsing a text file (and then putting that into a CSV file or database) that is tab separated but not sure what language I should be looking at using for this.

I guess most will do it (Perl?).

The end result I want to put the data into a database of somekind and then into GNUPlot (which I’m also learning to use!)

Perl is your parsing friend, How is the file formatted?

It’s in tabbed format. So

Data {tab} Data {tab} Data {tab} Data
Data {tab} Data {tab} Data {tab} Data
Data {tab} Data {tab} Data {tab} Data

I only want various rows though - however after some google searching I can get a CSV file of the data I’m after anyhow already. From there I need to figure out how to use GNUplot to do the data as this stores the data for a while. :slight_smile:

No, my mistake - The CSV data is good but requires some editing to make it able to be used in GNUplot - ie the first row is column names - these need deleting or commenting out and the commas need replacing with spaces or tabs. I’ll have a play.

GNUplot is being learnt for work and thus I was messing with trying to construct a personal stats for folding. Seem to have constructed a graph with some manually editing of the CSV file, now I need to play with creating a script to run it automatically and create the graph.

google up “perl split”

Once data portions are in a variable you can just use printf to format your output as necessary

go old school with awk! (and possible sed) :smiley:

What he said :slight_smile:

man awk
man sed

Make a Schema.ini and bang at it using Access,VB etc…

Format=TabDelimited ’ or you could use format=Chr(9) etc…
Col1=F1 Long
Col2=F2 DateTime
Col3=F3 Long
Col4=F4 Long
Col5=F5 Text
Col6=F6 Text
Col7=F7 Text
Col8=F8 Text

Using sed I can remove the first line with the command

sed /TimeStamp/d user.csv > output.csv

However I cant change the commas to spaces (they’ll probably be no issues on Linux but with Windows Sed…) I get the error that s hasn’t terminated.

The code is

sed s/,/ /g output.csv > output1.txt

using ‘s/,/ /g’ wont work as it says unknown command ’ whilst s/,/\ /g doesn’t work either. Any ideas?

s/,/./g works though!

Solved. I found that inserts a tab so the code is now

sed s/,/	/g output.csv > output1.txt