your programing

메모장 ++ 증분 교체

lovepro 2020. 10. 9. 11:32
반응형

메모장 ++ 증분 교체


10 개의 데이터 행을 갖고 싶지만 각 행 또는 데이터 조각에 대해 값이 증가하고 싶다고 가정 해 보겠습니다. 그 값을 어떻게 증가합니까?

예를 들어 ....이 행이 있으면 ID 값을 증가시키는 정규식 방법이 있습니까?

<row id="1" />
<row id="1" />
<row id="1" />
<row id="1" />
<row id="1" />

--- 내가 원하는 모습은 ... (첫 번째 행의 ID가 올라가면 괜찮습니다)

<row id="1" />
<row id="2" />
<row id="3" />
<row id="4" />
<row id="5" />

정규식에 대해서는 확실하지 않지만, 유연하지는 않지만 Notepad ++에서이 작업을 수행 할 수있는 방법이 있습니다.

제공 한 예 Alt에서 변경하려는 숫자 열을 누른 상태 에서 선택하십시오. 그런 다음 나타나는 창에서 라디오 버튼으로 이동하여 Edit->Column Editor선택합니다 Number to Insert. 그런 다음 초기 번호와 증분을 지정하고 확인을 누르십시오. 증가 된 숫자를 써야합니다.

참고 :이 Multi-editing기능 과 함께 작동 합니다 ( Ctrl키를 누른 상태에서 여러 위치 선택 ).

그러나 이것은 대부분의 사람들이 유용하다고 생각하는 유연성에 가깝지 않습니다. Notepad ++는 훌륭하지만 이와 같은 작업을 쉽게 수행 할 수있는 진정으로 강력한 편집기를 원한다면 Vim을 사용하십시오.


나는 오늘 같은 기능을 찾고 있었지만 메모장 ++에서 이것을 할 수 없었습니다. 그러나 우리를 구하기 위해 TextPad가 있습니다. 그것은 나를 위해 일했습니다.

TextPad의 바꾸기 대화 상자에서 regex를 켭니다. 그런 다음 교체를 시도 할 수 있습니다.

<row id="1"/>

으로

<row id="\i"/>

TextPad를 더 놀라운 대체 기능이 링크에서보세요 - http://sublimetext.userecho.com/topic/106519-generate-a-sequence-of-numbers-increment-replace/


실제 답변이 제한되어 있으므로이 해결 방법을 공유하겠습니다. 내용은 정말 당신의 예와 같이 간단한 경우 당신은 그것을 거꾸로 할 ...

이것으로부터

1
2
3
4
5

교체 \r\n" />\r\n<row id="당신은 방법의 90 %를 얻을 것이다있다

1" />
<row id="2" />
<row id="3" />
<row id="4" />
<row id="5

또는 엑셀 / 스프레드 시트로 데이터를 해킹 할 수있는 유사한 방식입니다. 원본 데이터를 열로 분할하고 필요에 따라 값을 조작하기 만하면됩니다.

|   <row id="   |   1   |   " />    |
|   <row id="   |   1   |   " />    |
|   <row id="   |   1   |   " />    |
|   <row id="   |   1   |   " />    |
|   <row id="   |   1   |   " />    |

분명한 일이지만 이상한 일회성 해킹 작업을 수행하여 몇 가지 키 입력을 저장하는 데 도움이 될 수 있습니다.


http://docs.notepad-plus-plus.org/index.php/Inserting_Variable_Text

Notepad ++에는 두 가지 다른 방법으로 직사각형 선택에서 작업 할 수있는 편집-> 열 "Alt + C"편집기가 장착되어 있습니다. Coledit.png 삽입 열에서 현재 줄을 포함하고 그 뒤에 오는 모든 줄에 고정 텍스트 삽입 포인트 (캐럿). 처음에 선택한 텍스트는 그대로 유지됩니다. 그림에서 알 수 있듯이 일련의 선형 숫자를 동일한 방식으로 삽입 할 수 있습니다. 시작 값과 증분이 제공됩니다. 0이있는 왼쪽 패딩은 옵션이며 숫자는 2 진법, 8 진법, 10 진법 또는 16 진법으로 입력 할 수 있습니다. 이것은 계산 된 값도 표시되는 방식이며 패딩은 가장 큰 것을 기준으로합니다.



위에서 제안한 솔루션은 데이터가 정렬 된 경우에만 작동합니다 ..
PythonScript Notepad ++ 플러그인을 사용하는 링크의 솔루션을 참조하십시오 . 잘 작동합니다!

stackoverflow 찾기 / 바꾸지 만 값 증가


나는 250 줄이 넘는 동일한 문제가 있었고 여기에 내가 한 방법이 있습니다.

예 :

<row id="1" />
<row id="1" />
<row id="1" />
<row id="1" />
<row id="1" />

커서를 "1"바로 뒤에 놓고 alt + shift아래쪽 화살표 를 클릭 하여 아래쪽 줄에 도달 할 때까지 내림차순을 시작합니다. 이제 선택 그룹이 표시됩니다. 지우기를 클릭하여 각 줄의 숫자 1을 동시에 지우고 이동하여 Edit -> Column Editor선택합니다. Number to Insert그런 다음 1초기 번호 필드와 필드 1증가에 입력하고 0 번호를 확인하고 클릭ok

축하합니다 :)


(누군가가 사용할 수있는 경우 게시).

나는 OP보다 조금 더 복잡한 문제에 대한 해결책을 찾고 있었다-모든 항목을 숫자로 같은 숫자로 바꾸는 것

예를 들어 다음과 같이 교체합니다.

<row id="1" />
<row id="2" />
<row id="1" />
<row id="3" />
<row id="1" />

이것에 의해서:

<row id="2" />
<row id="3" />
<row id="2" />
<row id="4" />
<row id="2" />

Couldnt find the solution online so I wrote my own script in groovy (a bit ugly but does the job):

 /**
 * <p> Finds words that matches template and increases them by 1.
 * '_' in word template represents number.
 *
 * <p> E.g. if template equals 'Row="_"', then:
 * ALL Row=0 will be replaced by Row="1"
 * All Row=1 will be replaced by Row="2"
 * <p> Warning - your find template might not work properly if _ is the last character of it
 * etc.
 * <p> Requirments:
 * - Original text does not contain tepmlate string
 * - Only numbers in non-disrupted sequence are incremented and replaced
 * (i.e. from example below, if Row=4 exists in original text, but Row=3 not, than Row=4 will NOT be 
 * replaced by Row=5)
 */
def replace_inc(String text, int startingIndex, String findTemplate) {
    assert findTemplate.contains('_') : 'search template needs to contain "_" placeholder'
    assert !(findTemplate.replaceFirst('_','').contains('_')) : 'only one "_" placeholder is allowed'
    assert !text.contains('_____') : 'input text should not contain "______" (5 underscores)'
    while (true) {
        findString = findTemplate.replace("_",(startingIndex).toString())
        if (!text.contains(findString)) break;
        replaceString = findTemplate.replace("_", "_____"+(++startingIndex).toString())
        text = text.replaceAll(findString, replaceString)
    }
    return text.replaceAll("_____","") // get rid of '_____' character
}

// input
findTemplate = 'Row="_"'
path = /C:\TEMP\working_copy.txt/
startingIndex = 0

// do stuff
f = new File(path)
outText = replace_inc(f.text,startingIndex,findTemplate)
println "Results \n: " + outText
f.withWriter { out -> out.println outText }
println "Results written to $f"

You can do it using Powershell through regex and foreach loop, if you store your values in file input.txt:

$initialNum=1; $increment=1; $tmp = Get-Content input.txt | foreach {  $n = [regex]::match($_,'id="(\d+)"').groups[1
].value; if ($n) {$_ -replace "$n", ([int32]$initialNum+$increment); $increment=$increment+1;} else {$_}; }

After that you can store $tmp in file using $tmp > result.txt. This doesn't need data to be in columns.

참고URL : https://stackoverflow.com/questions/7602816/notepad-incrementally-replace

반응형