How do I convert a delimited list to a multicolumn table in excel?

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

stonewareslord

Posted 2013-08-24T15:06:35.443

Reputation: 43

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.940

The 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.200

2Try 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.797

This would also be trivial to do in Python. – martineau – 2013-08-24T19:44:55.120

Answers

0

My answer came from user49740:

sed -re 's/([^;]*);([^;]*);([^;]*);([^;]*);?/\1,\2,\3,\4\n/g' input.txt > output.txt

The first half of the string:

([^;]*);([^;]*);([^;]*);([^;]*);?

Finds 4 groups of ([^;]*) (all characters before the semicolon) then a semicolon. The second half:

\1,\2,\3,\4\n

Changes the text to CSV format. > output.txt will write the converted file to output.txt.

stonewareslord

Posted 2013-08-24T15:06:35.443

Reputation: 43

1

VBA macro to split entire rows to multiple rows

enter image description here

With this macro you split entire rows to multiple rows. You can choose how many columns your want after splitting. just change the value for iSplit at the first line. I don't use a specific delimiter, just column counts.

I commented every step. It's easy to adjust the macro to your personal needs.

  1. Open Excel and VBA editor with Alt+F11
  2. On the left pane, paste the code under the sheet where your data is placed
  3. Modify the first two lines according to your needs
  4. Execute the macro with F5

Const iSplit = 4    '## how many columns do you want after splitting

Sub transposeColumn()
    '## search the last row to know how many rows we have to iterate through
    iLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row

    '## begin to loop through every row. Begin at last row and go upwards
    For r = iLastRow To 1 Step -1

        '## search the last column in the current row
        iLastCol = Rows(r).Find("*", Cells(r, 1), , , xlByColumns, xlPrevious).Column

        '## calculate how many new rows we need to insert for this row
        iNewRows = WorksheetFunction.RoundUp(iLastCol / iSplit, 0) - 1

        '## begin to copy and insert new rows, one by one
        For c = 1 To iNewRows

            '## insert a new blank line where we can copy values to
            Rows(r + c).Insert Shift:=xlDown

            '## set the source range for easier access later
            Set rngSrc = Range(Cells(r, iSplit * c + 1), Cells(r, iSplit * c + iSplit))

            '## copy and paste the range
            rngSrc.Copy Destination:=Cells(r + c, 1)

            '## clear all cells which we have just copied
            rngSrc.Clear
        Next c
    Next r
End Sub

nixda

Posted 2013-08-24T15:06:35.443

Reputation: 23 233

0

If the list is a text file, you can use the Text Import Wizard in Excel. I assume there is a similar tool in both LibreOffice and Openoffice.org.

However, since the delimiters are the ; signs, when you import there will be a need to arrange the data as it will be imported as a row of values. You can alter the original text file and add another delimiter that signifies the next row.

Doktoro Reichard

Posted 2013-08-24T15:06:35.443

Reputation: 4 896

I think stonewareslord is looking for an automated method, i.e. one that does not require manual arrangement of data. – user49740 – 2013-08-24T16:08:41.100

He didn't explicitly declare that he wants a 100% automated way, he said he wanted to use LO/OO/Excel. Unless he uses Macros (and that is only part of Excel AFAIK), other than replacing 2 characters, I don't recall another option. If he did want a script in Perl, Python, etc, then this question would be better suited for SO. – Doktoro Reichard – 2013-08-24T16:11:45.947

Well, the above is just an example. I need to run this on a document with about 500 rows in it, so manual is close to impossible. – stonewareslord – 2013-08-24T18:17:58.063