0

My data looks like this:

7DigitNumbers(tabspace)IRRELEVANTSTUFF123(tabspace)30

example:

2712061    really irrelevant words and numbers     30

What I'm trying to get is:

7DigitNumbers(tabspace)30

on the same example:

2712061     30 

I've tried several combinations on notepad++ via find&replace function, but couldn't figure it out. Could you help me?

Thanks in advance, Mit

4

3 に答える 3

1

DonHoがRegExバックトラックをNotepad++ネイティブ置換に追加したようです。ここ
からメモ帳6.1.1をダウンロードし ます。メモ帳6.1.1をインストールし、[検索]->[置換]に移動します。

Find what:    ^([0-9]{7})(\t).*([0-9]{2})$  
Replace with: \1\2\3

[すべて置換]ボタンをクリックします

于 2012-04-20T21:50:07.860 に答える
1

Windows 用の awk のコピーを取得します (例: gawk )。次のコマンドを使用しますawk "{print $1,$NF}"。これにより、最初と最後の列が出力されます (NF はフィールドの数)。

データをファイルに複製し、いくつかの単語の間にいくつかのタブを追加する簡単なテストでは、次の結果が得られます。

C:\temp>awk "{print $1 \"\t\" $NF}" z.dat
2712061 32
2712062 31
2712063 30

awk print ステートメントはすべての引数を連結するため、最初と最後の列の値が 1 つのタブ文字で区切られます。

于 2012-04-20T14:59:07.087 に答える
0

Python 正規表現の検索と置換には、 PythonScript Notepad++ プラグインを使用します。機能
についてはこちら

Editor.pyreplace(search, replace[, count[, flags[, startLine[, endLine]]]])  

Editor.pymlreplace(search, replace[, count[, flags[, startPosition[, endPosition]]]])  

Python 正規表現の検索と置換関数 editor.pyreplace()
を使用した簡単なプログラムを次に示します。関数の実行中に何が起こっているかを確認できるように、多くのデバッグ コードを残しました。

# $Revision: 1.3 $
# $Author: dot $
# $Date: 2012/04/19 00:03:26 $

from Npp import *
import re, string

expression = notepad.prompt(
                 "Enter the search string on the first line, followed by Ctrl+Enter, \n" +
                 "followed by the replace string on second line",
                 "RegEx and Search/Replace" ,
                 "")

debug = True
#debug = False

if debug:
    bufferID = notepad.getCurrentBufferID()

if debug:
    # Show console for debugging
    console.clear()
    console.show()

if expression != None:
    expressionList = re.split(r"[\n\r]+", expression)

    if debug:
        console.write( expression + "\n" )

    if len(expressionList) == 2:
        if debug:
            console.write( "'" + expressionList[0] + "', '" + expressionList[1] + "'\n" )

        # First we'll start an undo action, then Ctrl-Z will undo the actions of the whole script
        editor.beginUndoAction()

        if debug:
            console.write( 'editor.pyreplace( r"%s" % expressionList[0], r"%s" % expressionList[1], 0, re.IGNORECASE)\n' )

        editor.pyreplace( r"%s" % expressionList[0], r"%s" % expressionList[1], 0, re.IGNORECASE)

        # End the undo action, so Ctrl-Z will undo the above two actions
        editor.endUndoAction()

# Debug
if debug:
    notepad.activateBufferID(bufferID)

このスクリプトを Notepad++ ショートカット (つまり Ctrl+r) にリンクした後、

^([0-9]{7})(\t).*([0-9]{2})$  

と置き換えます

\1\2\3

このスクリプトを Notepad++ ショートカットにマップしてCtrl+<ChooseALetter>実行します。
このスクリプトをテストしたところ、うまく機能しました。

于 2012-04-20T17:16:18.263 に答える