shift columns using regex

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
C0ppert0p
Posts: 12
Joined: Wed Aug 17, 2011 4:09 pm

shift columns using regex

Post by C0ppert0p »

I want to be able to shift everything from position x to the end of the line , back to position x. using regex
This can be done with block mode; selecting everything after a certain position and then using the reduce indent button.

I have huge files that may have lines anywhere from 20 to 600 characters long. Selecting a 6,000 lines from a fixed position to the end of the longest line is problematic.

Thanks in advance
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

Your problem description is unclear. Can you please provide examples of the data before and after the change? Please enclose the data in

Code: Select all

[/color][/b]...[b][color=blue][/code ][/color][/b] tags to retain the whitespace and layout.
C0ppert0p
Posts: 12
Joined: Wed Aug 17, 2011 4:09 pm

Post by C0ppert0p »

Sure thing:

before

Code: Select all

data                               more data more data more data more data 
data                    more data more data more data more data more data more data more data more data  more data more data more data
data                                           more data more data more data more data more data more data more data more data
data                       more data more data more data more data more data more data more data more data more data more data more data more data more data more data
data                                                           more data more data more data more data more data more data more data more data
After:

Code: Select all

data                more data more data more data more data more data
data                more data more data more data more data more data more data more data more data more data more data more data
data                more data more data more data more data more data more data more data more data
data                more data more data more data more data more data more data more data more data more data more data more data more data more data more data
data                more data more data more data more data more data more data more data more data
There are over 6000 lines of this. All lines are variable in length; from as few as twenty to hundreds of characters.
There are many of these files
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

To use the Reduce indent command you don't need to select all the text to the right. Select a single character in the first line and extend the selection to the bottom of the file with the Select to end of document command (<Ctrl+Shift+End>).
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

If you want to use regular expressions, firstly enable POSIX regular expression syntax in Configure > Preferences > Editor.

Then, to always leave 16 spaces after data (where there are 16 or more spaces originally), perform a Replace operation as follows:

Find what: (data_{16})_*(.*) (replace the underscores with spaces)
Replace with: \1\2
Post Reply