Setting a Column to a fixed value in a text file
-
Next to set specific column within a large text file to a specific value, say Column 10 = “X”, column 32 = “Z” etc.
Can I do this with a macro or ?? -
Yes, you probably can.
You’re going to have to give more details about the text you’re trying to format to get a better answer than that though. What defines a ‘column’ (tabs, commas, special characters)? Are the columns encapsulated in quotes? If you can give some specifics and maybe several example lines from the text file, I’m sure you’ll get an answer that helps.
-
- Put your caret in the desired column (e.g. 10) on line #1.
- Press Shift+Alt+DownArrow until you get to the last line of your file (stay in same column).
- You should now have what appears to be a really tall and skinny caret (assuming your are in INS mode; check status bar for INS vs OVR).
- Type the “fixed value” character that you want to have in your desired column.
- If you wanted to replace the original column content with your fixed-value character (rather than insert it), press the Delete key once.
If your file has a large number of lines, there are alternative steps to the 2nd step…to make it less onerous…
-
Hello @chuck-ballinger,
An other possibility is to use regular expressions !
Let’s suppose that you want to insert a
X
character, in columnn
, on any line of your file :-
Open the Replace dialog ( Ctrl + H )
-
OPTIONS
Wrap around
andRegular expression
checked -
SEARCH
(?-s)^.{
n-1}\K\x20+(?=(X))|^.{0,
n-1}\K
( Replace the expressionn-1
with the appropriate number ! ) -
REPLACE
?1:
n spacesX
-
ACTION click TWICE on the
Replace All
button
So, assuming the initial text, below, with a first blank line :
1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 12345678901 123456789012 1234567890123 12345678901234 123456789012345
After two click on Replace All, we get the text :
X 1 X 12 X 123 X 1234 X 12345 X 123456 X 1234567 X 12345678 X 123456789X 123456789X0 123456789X01 123456789X012 123456789X0123 123456789X01234 123456789X012345
If you like that solution, I’ll give you, next time, some details on that regex S/R !
Best Regards,
guy038
-