I am not sure if this will do it for you.

cat sample.txt | tr ',' '.' | awk '{ out="fl_gr"$1"mw.txt" ; if ($2 ==
2) out="fl_gr"$1"wm.txt" ; $1=$2=""; print  $0 > out}'




On Wed Jan 14,2009 06:01 pm, Linus Neumann wrote:
> 
> Dear all,
> 
> to continue with my diploma thesis, I have a particular problem to  
> solve and I believe that VIM-scripting might be the most convenient  
> way to do so - please correct me, if I am wrong.
> 
> I have no more than very basic programming or scripting skills, so I  
> will have to rely on your generous help to finish my research. In the  
> publication I will of course officially thank whoever helped me to  
> solve the problem.
> 
> As for the problem:
> 
> What needs to be done? (irrelevant background)
> Data from SPSS needs to be converted into a .txt-Format that fits the  
> conventions of a particular R-script.
> SPSS-data can be provided either as tab-delimited .dat- or semicolon- 
> seperated .csv-file - one of these should be the used by the VIM-script.
> 
> What is the script supposed to do? (relevant)
> The .dat or .csv file needs to be split up into seperate .txt-Files,  
> based on certain variables, that are contained in the .dat/.csv-file.
> 
> Here for a (shortened) example:
> 
> .dat-file might look like this:
> 
> 1     1       6,83333333333333        5,66666666666667        
> 5,91666666666667        
> 1     1       4,75    6,33333333333333        5,25    6       
> 6,33333333333333        
> 1     1       4,91666666666667        4,66666666666667        6,08333333333333
> 1     2       6,08333333333333        5,33333333333333        5       
> 1     2       4,58333333333333        4,91666666666667        5,41666666666667
> 1     2       4,33333333333333        3,5     5       5,16666666666667
> 2     1       ....
> 2     2       ....
> 3     1       ....
> 3     2       ....
> 
> The relevant information for splitting the file are the first 2  
> variables.
> The result of the script should be seperate files, each with the  
> following contents:
> 
> File fl_gr1mw.txt
> 6.83333333333333      5.66666666666667        5.91666666666667        
> 4.75  6.33333333333333        5.25    6       6.33333333333333        
> 4.91666666666667      4.66666666666667        6.08333333333333
> 
> File fl_gr1wm.txt
> 6.08333333333333      5.33333333333333        5       
> 4.58333333333333      4.91666666666667        5.41666666666667
> 4.33333333333333      3.5     5       5.16666666666667
> 
> File fl_gr2mw.txt
> ....
> 
> File fl_gr2wm.txt
> ....
> 
> File fl_gr3mw.txt
> ....
> 
> File fl_gr3wm.txt
> .... (Contents following the 3 2 combination)
> 
> and so on
> 
> To sum it up:
> - Var 1 is the file number: fl_grVAR1
> - Var 2 determines mw/wm: fl_grVAR1VAR1.txt
> - File should only contain data for the corresponding VAR1/VAR2- 
> combination, yet not VAR1 & VAR2
> - Attention:
>       - lines are much longer (not only five, but ranges of 13 to 18  
> variables per line - script should adjust to that)
>       - script needs to be run on a total of 1800 lines in 6 seperate  
> files, each having different numbers of variables - so it should be  
> fairly adjustable. By the way: Now you see why I need a script to do  
> this)
>       - if possible, tabs (.dat) or semicolons (CSV) should be converted to  
> simple single space ( ) (Probably I can find a way for SPSS to do this  
> in the first place)
>       - if possible, commas (,) should be converted to dots (.) (Probably I  
> can find a way for SPSS to do this in the first place)
> 
> So, this is it already!
> 
> For all I know this is just a couple of loops and if-thens - yet a lot  
> of KNOW-HOW, which I lack.
> So, if anyone has the time, I would greatly appreciate your help.
> 
> Thank you VERY much,
> 
> Linus Neumann, Humboldt-University of Berlin
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to