3
I have a list like this:
Friut;Taste;Color;Other;Apple;Good;Red and Blue;1;Orange;Really Good;Orange;12
And I want to convert it by selecting every 4 delimitations and turning them into rows like this:
Fruit Taste Color Other
Apple Good Red and G.1
Orange Really Go.Orange 12
How is this possible with Libreoffice (preferred), Openoffice, or Excel?
Edit: The above is an example. I am using it to select 4 delimitations, but there are about 500 rows that I need this to work on.
Edit2: Provided my own (correct) answer
2It would be easier to do this with something like Perl or sed .
echo "Your string" | perl -pe 's/([^;]*);([^;]*);([^;]*);([^;]*);?/$1,$2,$3,$4\n/g'
and import the result as CSV. Do you really need a solution that uses LO/OO/Excel and nothing more? – user49740 – 2013-08-24T15:35:10.940The way you have it listen now, each fruit is a row, as far as character delimited files go... – Austin T French – 2013-08-24T15:58:48.507
I don't really know Perl, and that that looks like a regex string, which I also don't know. This is really cool, I will try this on my document. Is there a way to make this also work with newline? – stonewareslord – 2013-08-24T15:58:57.157
Please explain "make this also work with newline". Update your question with an example.
Also, you should learn Perl and regexes, they are very helpful in dealing with text. – user49740 – 2013-08-24T16:07:13.843
I just meant with a new line, but it doesn't matter. How do I do this with sed? I am trying to run:
sed -e 's/([^;]*);([^;]*);([^;]*);([^;]*);?/$1,$2,$3,$4\n/g' file.txt
, but it's not working (it's just returning the contents of the file) – stonewareslord – 2013-08-24T16:15:53.2002Try
sed -re 's/([^;]*);([^;]*);([^;]*);([^;]*);?/\1,\2,\3,\4\n/g' file.txt
. That-r
is important, and$1, $2,...
are\1, \2,...
in sed syntax. – user49740 – 2013-08-24T16:34:23.797This would also be trivial to do in Python. – martineau – 2013-08-24T19:44:55.120