How to re-order pipe-delimited columns in Notepad++?
Solution 1:
Re-ordering Columns in a Text File
Yes this is possible within vanilla Notepad++
, though as noted there are also plugins that will do it. A better (more robust) approach might be to use some command-line text-processing tools, but if you need a quick-and-dirty solution you can find that below:
Assuming your exact input (col1|col2|col3
, pipe delimeter, no pipe in col2
):
Find: (.*?)\|(.*?)\|(.*)
Replace: \1|\3|\2
works for me here in Notepad++
, built Jan 2015. Somewhat brutish, but it works.
Explanation:
.*
- matches any character (except newline), between zero and unlimited times
.*?
- matches any character (except newline) as above, in a non-greedy manner (ie match as little as possible)
(.*)
- plain brackets denote capturing group of above (to use in Replace as eg \1
, \2
, \3
etc )
\|
- \
escapes pipe (|
) to match it literally
\1|\3|\2
- print 1st matching group, pipe, third matching group, pipe, second matching group