Switch word postions in Notepad ++ - text

My text looks like this:
Text1 | Text2 | Text3 | Text4 | Text5 | Text6 | Text7
And I want to change text positions like this
Text1 | Text4 | Text5 | Text6 | Text2| Text3 | Text7
And if it's possible to remove the | between Text 4, 5, 6, so that it looks like
Text1 | Text4 Text5 Text6 | Text2 | Text3 | Text7
If it is not possible, I'll be happy if the first problem is solved.

You may use
^([^|]*\|)((?:[^|]*\|){2})((?:[^|]*\|){3})
And replace with $1$3$2.
Details:
^ - start of a line
([^|]*\|) - Group 1 ($1) capturing zero or more chars other than | and then a literal |
((?:[^|]*\|){2}) - Group 2 ($2) capturing 2 sequences of the same pattern as in Group 1
((?:[^|]*\|){3}) - Group 3 ($3) capturing 2 sequences of the same pattern as in Group 1
The order is changed with the order of the backreferences in the replacement pattern.
To remove the 2nd, 3rd and 4th |, use a similar expression:
Find what: ^([^|]*\|)([^|]*)\|([^|]*)\|([^|]*)
Replace with: $1$2$3$4
Basically, you just manipulate the capturing group boudaries and the order of the backreferences in the replacement pattern, that is all.

Related

Convert from Text to Columns in Excel

I have following input in text format:
|Number|Name|SUMinRUB|Reason
|-|Table|1000|This is Text
| | | |Splitted in
| | | |Seveal Lines
|2|Chairs|2000|This is another
| | | |Text splitted
| | | |In several lines
And when converting to Excel, Reason column is converted into several lines. I need, to make it like this:
Result in Excel
You must replace "||||" to "" (empty string) or " " (space) (Find&Select -> Replace) in whole file before using the TextToColumns function.

Postgres 9.4+ split an alpha numeric string into two columns

I need to deal with the following and after searching I wasn't able to find exactly what I'm looking for:
Let's say I have a column which may or may not have an alphanumeric string
SKU
-----
12345ABC
12345-Abc
12345-Ab23
12345
Which I would like to break into
SKU | BATCH
------------------
12345 | ABC
12345 | Abc
12345 | Ab23
12345 | NULL
using PostgreSQL 9.4+ I've tried the string and sub_string method's but I'm not getting the results I'm looking to achieve... any ideas?
You can use the substring function.
with a (SKU) as (values('12345ABC'), ('12345-Abc'), ('12345-Ab23'), ('12345'))
select substring(sku from '^\d+'), substring(sku from '[a-zA-Z][a-zA-Z0-9]*$') from a;
substring | substring
-----------+-----------
12345 | ABC
12345 | Abc
12345 | Ab23
12345 |
(4 rows)
You can use regexp_matches:
with a (SKU) as (values('12345ABC'), ('12345-Abc'), ('12345-Ab23'), ('12345'))
select res[1], res[2]
from (
SELECT regexp_matches(SKU, '(\d+)[^[:alnum:]]*([[:alnum:]]+)?') res
FROM a
) y;

How to align multiline values in AsciiDoc table?

I would like to dynamically generate a table with asciidoc, which could look like this :
--------------------------------------
|Text | Parameter | Value1 | Value2 |
--------------------------------------
|foo | param1 | val1 | val2 |
--------------------------------------
|bar | param2 | val3 | val4 |
| | param3 | value_ | val6 |
| | | multi_ | |
| | | 5 | |
| | param4 | val7 | val8 |
--------------------------------------
| baz | param5 | val9 | val10 |
--------------------------------------
That is, there might be multiple parameters to one text, and their
values might span multiple lines. I am looking for a way to automatically
align these. I have a program that gathers data which changes, so I can
not manually fix things.
What I currently do: I have frame and gridless nested tables in the
Parameter, Value1 and Value2 columns. The problem with this is they only align if each value does not span multiple lines.
I also tried making Parameter, Value1 and Value2 a nested table together, with grid but no frame.
It works in terms of alignment, but doesn't look very good because the grid lines do not touch the gridlines of the outer table. Adding a frame also looks dull since it emphasizes multiparameter entries.
What I really want to do is add an extra line to the outer table (no table nesting) with no horizontal line in between, if there is an extra parameter.
I can not see how to do this with AsciiDoc. Is that possible at all? Any other suggestions on how to solve this?
It turns out this is rather easy with spans (see chapter 23.5):
.Multiline values alined with spans
[cols=",,,",width="60%", options="header"]
|================
|Text | Parameter | Value1 | Value2
|foo | param1 | val1 | val2
.3+<.<|foo .3+<.<|bar | val3 | val4
| razzle bla fasel foo bar | dazzle
|bli | bla
|foo2 | param3 | val5 | val6
|================
Now all I need to do is tell my templating system (jinja2) how much rows I need to span, but that is rather a diligent but routine piece of work.
If you're using asciidoctor, there are many other options for tables including putting columns on new lines and using the metadata for the table to specify how many columns the table contains. This is the recommended way of doing tables in Asciidoctor. You can see this example and many others in the user's guide. To give an example here on SO:
[cols="2*"]
|===
|Cell in column 1, row 1
|Cell in column 2, row 1
|Cell in column 1, row 2
|Cell in column 2, row 2
|===
Asciidoctor can be a drop in replacement for the asciidoc command, though you will want to look at differences between the two.

Can I escape the pipe in specflow (or gherkin)

I've got a specflow step table that I want to have the | (pipe) character as a part of the content.
Example:
Then the data should be
| Field | Value |
| SomeField | a|b|c |
But this doesn't work. How can I escape the pipe character?
Bah. I can't believe I didn't find this earlier. You CAN escape a pipe with the backslash, but the specflow syntax highlighter gets confused by it.
Then the data should be
| Field | Value |
| SomeField | a\|b\|c |

How to search for the Nth match in a line in Vim?

I am editing a wiki file and would like to add a new column in between of two existing columns.
| *No* | *Issue* | *File* | *Status* |
| 1 | blah | foo | open |
| 2 | blah1 | foo1 | close |
Say, I want to insert a new column between the 3rd and 4th columns above. If I could search for the fourth match of the | character in a given line, I could replace that with | |. But how one can do that in Vim?
The end result would look like so:
| *No* | *Issue* | *File* | | *Status* |
| 1 | blah | foo | | open |
| 2 | blah1 | foo1 | | close |
How about recording a macro into register q by entering qq3f|a|<ESC>q in command mode (ESC means pressing the Escape key). Now you can apply this macro to each line by :%norm#q.
Additional bonus:
With this pattern you can add more complex actions, for example replicate the first column as column 3 (if cursor is at first column):
qqf yf|;;;p0q
Oh, and the answer to your question: Search 4th occurrence of | on a line is done by 3f| (if the cursor is at position 0 and on a | character as in your example).
Consider the following substitution command.
:%s/\%(.\{-}|\)\{4}\zs/ |/
:%s/\(|[^|]*\)\{3\}/&| /
Which means: on each line (%), find three occurrences (\{3\}) of a string that starts with | followed by any number of non-| ([^|]*), and replace that with itself (&) followed by |.
You can call sed in vim as a filter:
:%!sed 's/|/| |/4'

Resources