0

I have a text file with a long list of variables like this:

a VARCHAR(32),
b INT,
c TINYINT,
.
.
.

I want to quickly swap the order of the name and type so I have:

VARCHAR(32) a,
INT b,
TINYINT c
.
.
.

Im happy to use a bash terminal or notepad ++ and I do have a basic knowledge of regex but Im not sure how to tackle this problem.

How can I go about doing this?

Connor Bishop
  • 921
  • 1
  • 12
  • 21

1 Answers1

1

you can use this app I just wrote: http://codepen.io/franzskuffka/pen/Ndxejz

Or run it through this function

function swap (text) {
    let lines = text.split(',\n')
    let parts = lines.map(function (line) {
        var lineParts = line.split(' ')
        lineParts[2] = lineParts[0]
        delete lineParts[0]
        return lineParts.join(' ')
    })
    return parts.join(',\n')
}

Generally I recommend the text editor Kakoune for this task which is awesome for text processing in general due to the multicursor support and incremental editing.

Jan Wirth
  • 411
  • 2
  • 13