How to merge 2 columns to one in TextMate?

3

Anyone knows how would one merge such list as

item 1  item 2
item 3  item 4

to

item 1 
item 2 
item 3 
item 4 

in TextMate or TextWrangler?

Dan

Posted 2011-07-08T09:11:23.207

Reputation: 191

Answers

1

How are the columns separated? By a \t? If so, you just want to replace this with a newline. If they aren't separated by a tab, the procedure is the same – just copy the column separator, whatever it is. Two spaces for example should work just fine, as will a , when working witha CSV.

item 1  item 2
item 3  item 4

The procedure's fairly easy:

  • Copy the tab character from the text field with Cmd-C (it might help to have View → Show Invisibles enabled)

    enter image description here

  • Open a search/replace window with Cmd+F.

  • Paste the copied tab character into the "Find" field with Cmd-V.
  • In the "Replace" field, press alt+Enter to get a new line.

It'll look like this (yes, you can't see anything, but you can select the contents to see everything's there).

enter image description here

Then, click "Replace All". Result:

item 1
item 2
item 3
item 4

As @romainl points out, it's also possible to use Regular Expressions for that. If you know the separator is Tab (\t), just check "Regular expression" and enter \t for "Find" and \n for "Replace.

enter image description here

slhck

Posted 2011-07-08T09:11:23.207

Reputation: 182 472

One could also check the "Regular Expression" checkbox and type \t in the "Find:" textfield and \n in the "Replace:" textfield. – romainl – 2011-07-08T11:42:26.947

Yup, didn't want to include it at first because with Regular expressions you'd have to read up what to use if your separator is not \t. I added that to the answer though, thanks for pointing out. – slhck – 2011-07-08T11:52:57.407