Hi
I often do searches of log files in TextPad. when the results come out they are preceded by the filename and parenthetical line count then a colon. This is also great. But it means that the log record it's self does not line up correctly as some are prefixed with "filename.txt(1): " and some with "filename.txt(99999): ".
in order for me to quickly recognize some issues it is advantages for me to have the log records shown all line up. I have done this in the past manually adding one or many space(s) between the closing parenthetical and the colon. this is a problem however when the search results in 160000 results from eight to twelve files.
is there an easy way to align the text of a data file or the search results by inserting a variable number of spaces?
thanks very much.
Aligning text in a data set, or file.
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
I have done this in the past when the format was fixed on both ends. but unfortunately this is not the case here. The log file entry in this case has several fixed length entries on each line followed by a free form message. normally this makes it very easy to scan visually. But when using textpad to pull out some lines (usually by one of those afore mentioned values) and having the variable length appended to the front of the search results this is difficult.
I like having the files and line counts in the results. as well as being able to click and go to that file and line.
I like having the files and line counts in the results. as well as being able to click and go to that file and line.
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
Insert enough spaces between the close parentheses and the colons to shift the colons sufficiently to the right.
Turn on block select mode.
Select a block, one column wide, containing the leftmost colons. (<Shift+Ctrl+Home> and <Shift+Ctrl+End> are useful for this.)
Repeatedly replace a single space within that selection by nothing until all the colons line up.
Turn on block select mode.
Select a block, one column wide, containing the leftmost colons. (<Shift+Ctrl+Home> and <Shift+Ctrl+End> are useful for this.)
Repeatedly replace a single space within that selection by nothing until all the colons line up.
If I understand you correctly, aligning stuff in neat columns with TP is straightforward.
In the case of
filename.txt(99999): BlahBlahBlahBlahBlahBlahBlah, you need a tab (\t) following the colon - if you don't have access to specifying that it get written at the outset in the log file by the server, then you will need to use a regular expression Replace
Search: \():\) the \(\) escaped parens round what you're looking for captures what's found - which will be ):
Replace: \1\t - which says "what you captured followed by a tab".
Click Replace All, so that every instance of ): is followed by a tab. Next, with the log file still open in TP, press Alt+<return> to open up the properties Window.
and go to the Tabulation Page. In the 'Tab Stops' input box type in a number, say about 30, in the above instance, so the first tab will be at character 30. Press return, and all that follows that tab you inserted will align at character 30.
You can add multiple Tabstop values, and so multiple "column seperators" (tabs) on a line.
When trying to sort Such text out (database dumps), I find it easiest setting the first tabstop to something improbable like 1000 - which will shift all the stuff following the first tab right off screen (assuming you have wordwrap OFF (which should be the case)) - leaving just Column 1 showing. That way it's easy to quickly scroll down - find the longest column 1 entry. place the cursor at it's end, and read off, on the bottom status bar, where your next tab stop should be (add some on to space the columns a little). Go ahead and set this as your second tabstop. That will pull column 2 alongside column 1. Repeat for all columns. Finally remove the original 1000 tabstop to check there's no surprises lingering at the outer edges of your editing universe.
Now you can, Right click and select, 'Block Select mode' - that'll allow you to select"strips" of columns ready for Replace or Insert using the Edit:Fill Block.. command - very handy. - but remember, if you haven't planned, and your tabs don't have enough space between them, you'll have to adjust all the numbers in the TabStops box to get back those that jumped out of alignment. ( Do it and you'll see what I mean ) Also, the Tabstops doesn't get preserved, next time you open the file you have to re-enter them. A work arounf is to make a new Document Class for some weird extension (I use .sql), there you can define default Tabstops for every document of that type i.e. they get preserved. It would be far more useful if we coulf put a flag at the top of files like #%%30,45,123...
which Textpad responded to, and where the first characters cold be user defined - because different languages have different comment starters - Textpad would read spaces 5 and 6 for consequtive %'s
One more thing, Block select to include the tabs you added at the start, Search for \t and replace with nothing BUT... make sure the 'Selected text' option is chosen - or you could replace tabs elsewhere that should be retained.
In the case of
filename.txt(99999): BlahBlahBlahBlahBlahBlahBlah, you need a tab (\t) following the colon - if you don't have access to specifying that it get written at the outset in the log file by the server, then you will need to use a regular expression Replace
Search: \():\) the \(\) escaped parens round what you're looking for captures what's found - which will be ):
Replace: \1\t - which says "what you captured followed by a tab".
Click Replace All, so that every instance of ): is followed by a tab. Next, with the log file still open in TP, press Alt+<return> to open up the properties Window.
and go to the Tabulation Page. In the 'Tab Stops' input box type in a number, say about 30, in the above instance, so the first tab will be at character 30. Press return, and all that follows that tab you inserted will align at character 30.
You can add multiple Tabstop values, and so multiple "column seperators" (tabs) on a line.
When trying to sort Such text out (database dumps), I find it easiest setting the first tabstop to something improbable like 1000 - which will shift all the stuff following the first tab right off screen (assuming you have wordwrap OFF (which should be the case)) - leaving just Column 1 showing. That way it's easy to quickly scroll down - find the longest column 1 entry. place the cursor at it's end, and read off, on the bottom status bar, where your next tab stop should be (add some on to space the columns a little). Go ahead and set this as your second tabstop. That will pull column 2 alongside column 1. Repeat for all columns. Finally remove the original 1000 tabstop to check there's no surprises lingering at the outer edges of your editing universe.
Now you can, Right click and select, 'Block Select mode' - that'll allow you to select"strips" of columns ready for Replace or Insert using the Edit:Fill Block.. command - very handy. - but remember, if you haven't planned, and your tabs don't have enough space between them, you'll have to adjust all the numbers in the TabStops box to get back those that jumped out of alignment. ( Do it and you'll see what I mean ) Also, the Tabstops doesn't get preserved, next time you open the file you have to re-enter them. A work arounf is to make a new Document Class for some weird extension (I use .sql), there you can define default Tabstops for every document of that type i.e. they get preserved. It would be far more useful if we coulf put a flag at the top of files like #%%30,45,123...
which Textpad responded to, and where the first characters cold be user defined - because different languages have different comment starters - Textpad would read spaces 5 and 6 for consequtive %'s
One more thing, Block select to include the tabs you added at the start, Search for \t and replace with nothing BUT... make sure the 'Selected text' option is chosen - or you could replace tabs elsewhere that should be retained.
John Montgomery
Aberdeen, Scotland.
Aberdeen, Scotland.