Manipulate data
i have a long text file with
[QUOTE]
how do i change the file to Quote:
|
I'm afraid what you've given us is nothing but a long list of numbers, letters and dates. How are you going from one set of data to the other? None of my guesses seem to be consistent with the data you've given.
In any case, it looks like it's going to be a more complicated parsing job than just a simple sed/awk script (though I'm sure it could be done that way) so you'd be better off with python or perl or something like that. |
please note the pattern in the first column the conetent is the same, i just want to have all the fields of that column fow which its the same in the same row
|
Ah, is the 2nd date on line 2 now meant to be 11-20-2012? If so, I'll have a look at it.
Are all the 'a' lines going to be consecutive (same for b, c, etc.)? Are spaces always the delimiter? EDIT: If I was correct about all the above guesses, then I think this programme does what you want: Code:
#!/usr/bin/env python3 |
sorry, i have corrected that, yess they are all going to be consective and spaces are the delimeters, its just a long list with d's e's and so on
|
Ah, sorry, didn't see your latest post - I have edited my last post to include some code that I believe does what you want.
Hope this helps, |
thaks though wen i look at the code it seems to suggest the first column changeds in 3's whereas at some points it changes after four of 5, ie 5 a's it could be
|
It can be achieved simply by a piece of AWK code. I believe it would be much better than the tedious and heavy python codes.
And, it is more general than the previous solution from Snark1994, since here the code can generate the first line according to the file itself rather than specifying it manually as "n 1 2 3 D1 D2 D3". It dose not matter if you change your file to include more than 3 lines for a, b or c. The code bellow are able to adjust it according to the input file. Code:
awk '!/^$/{ |
Well I am glad everyone else picked up on the fact that the data included a header ... had me baffled :(
Anyhoo: Code:
ruby -ane 'BEGIN{l=[]};if ! l.empty? && l[0] != $F[0]; puts l.join(" ");l.clear;else l<<$F[0] if l.empty?;l<<$F.last;l.insert((l.count/2).ceil,$F[2]);end' file |
It always makes me cry on the inside a little when you do that, grail.
Sorry, arn2025, I didn't quite understand where you got your header line from - my code would work fine (it would print 4 or 5 numbers on the line) but it would only put "1 2 3" in the header. It would be easy to change it to do this properly too, but seeing as you've got two other solutions, I'll leave you with those. (Also, if you look, neither grail nor I found it easy to work out what exactly you needed doing - even when the gist of it was clear, the fact that you might get 4 or 5 similar rows, or the presence of a header, was not obvious. Next time you post a thread, perhaps give a bit of thought to explaining what you want clearly and precisely at the start. Just a heads up, I hope I'm not lecturing :) ) If you consider this problem to be solved, can you mark the thread as 'SOLVED' please? Thank you. |
Quote:
|
Quote:
|
Quote:
LQ member I got stuck in and really enjoy it :) You are right though, I need to remember to explain them a bit better :( Code:
-a - Split read lines using the default delimiter into the global array $F |
Mm, I do like ruby, mostly because of its support of functional programming - it bridged the gap between haskell and python, because I got to do a lot of the neat haskell tricks without having the hassle of very strict type checking and pure functions.
Yeah, definitely very nifty code :) @cristalp, have we solved your problem? If so, please remember to mark the thread as solved. |
All times are GMT -5. The time now is 02:59 AM. |