1

I'm looking for something similar to this question. However, I'd like to chose the amount of columns and export it as table.

My input is a .txt file with a single line and many numbers separated by a variable amount of spaces.

32 45 2.65   -845     1 -84    97.236        454   35.78 77.12    948.87       
         151    -23.5         -787.48     13.005   31

I know every x numbers (being x a fix amount in every file) there should be a break. For instance the first 4 numbers in 4 columns the first row, next 4 the second row and so on.

+-------+---------+--------+------+
| col1  |  col2   |  col3  | col4 |
+-------+---------+--------+------+
| 32    | 45      | 2.65   | -845 |
| 1     | -84     | 97.236 |  454 |
| 35.78 | 77.12   | 948.87 |  151 |
| -23.5 | -787.48 | 13.005 |   31 |
+-------+---------+--------+------+

Actually the objective is to create a .csv file with the right amount of columns. Is it possible to do this in Notepad ++?

Albert
  • 131

1 Answers1

2
  • Ctrl+H
  • Find what: (?:\A|\G)(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+
  • Replace with: $1,$2,$3,$4\n
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

(?:             # non capture group
   \A           # beginning of file
 |              # OR
   \G           # Restart from lastmatch position
)               # end group
(\S+)           # group 1, 1 or more non spaces
\s+             # 1 or more spaces
(\S+)           # group 2, 1 or more non spaces
\s+             # 1 or more spaces
(\S+)           # group 3, 1 or more non spaces
\s+             # 1 or more spaces
(\S+)           # group 4, 1 or more non spaces
\s+             # 1 or more spaces

Replacement:

$1,$2,$3,$4     # content of the 4 gcapture groups, comma separated, you can use any kind of separator
\n              # line feed, use \r\n for windows end of line

Screen capture (before):

enter image description here

Screen capture (after):

enter image description here

Toto
  • 19,304