Sort Lines acording to another document?
-
I don’t think there is any plugin that can sort the lines of file1 based on the order of lines in file2. And it’s doubtful that anyone would write a full plugin just to solve this specific problem for you. There is a PythonScript plugin, which allows writing scripts in Python that will automate things in Notepad++, and someone might take an interest in doing that.
But your problem statement is a little vague.
- Does your file really have the line numbers embedded in the text like you showed, or were you just adding in those prefix numbers to indicate the line numbers that Notepad++ shows? Because as it is, no one could just copy/paste your data to try it out
- Your specs are a bit vague. Do you want a blank line in file1 for every line in file2 that has
//
? If so, what about lines in file2 that are blank? or just a bunch of spaces? or don’t match the pattern? or xxxx - Where do you put a line from file1 that doesn’t match anything from file2?
Without that, and probably a bunch of other details that you’ve neglected to share, nobody would get the script to work the way you want it on the first try. And iterative code writing with an incomplete spec is a nightmare, especially when done through a forum on a volunteer basis.
This forum is not a code writing service, by the way; we exist to help each other use Notepad++ better, but Notepad++ isn’t always the right tool.
Speaking of the right tool, it sounds like you have a couple tables exported from a database, and you want to sort file1 to match the order of file2. That sounds a lot more like a database task than a text-editor/Notepad++ task. In which case, find a database forum to help you (though they will likely tell you they are not a code writing service, either).
----
Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
This same philosophy applies when we tell you that your data transformation cannot be easily accomplished with builtin features, and it sounds like a generic programming problem, which could be done in a programming language of your choice, or by using a scripting plugin inside Notepad++; or by writing a plugin for Notepad++. I do not recall ever seeing someone in this forum say they were willing to write plugins for free for anyone who makes a request. A lot more often, if the problem interests someone and they have an idea, I see someone (including myself) volunteer to write a script for a scripting plugin – but only with a well-defined problem that they have an idea for a solution for that interests them and that they have time for; if any of those conditions are not met, they usually don’t volunteer for it. And we are not a code-writing service, so you cannot expect that someone will write code to solve your problem for you, just because you are a Notepad++ user.
-
@PeterJones said in Sort Lines acording to another document?:
were you just adding in those prefix numbers to indicate the line numbers that Notepad++ shows?
I was just adding in those.
@PeterJones said in Sort Lines acording to another document?:
Your specs are a bit vague. Do you want a blank line in file1 for every line in file2 that has // ? If so, what about lines in file2 that are blank? or just a bunch of spaces? or don’t match the pattern? or xxxx
The important thing is that some lines are sorted as the second document.
The script should not add things like // or, or any thing.Bothe documents have the same “parameter text” but they are mixed upp.
Bothe could have a line like:
gaiusfdghpiuhsd_lisadfguyl_iygoigiugh = 0.54325
But in the first document it have some other numbers and are placed on line 243.
Document 2 on Line 42: gaiusfdghpiuhsd_lisadfguyl_iygoigiugh = 0.54325
Document 1 on Line 243: gaiusfdghpiuhsd_lisadfguyl_iygoigiugh = 0.54367
I want this part “gaiusfdghpiuhsd_lisadfguyl_iygoigiugh” to match in both documents, being on line 42.
After that I can run the Compare or ComparePlus and see what numbers that differs.
@PeterJones said in Sort Lines acording to another document?:
Where do you put a line from file1 that doesn’t match anything from file2?
Basicly any where is ok.
It could be as close as possible to its original line number or at the bottom.
I fully understand the note. But maybe someone of you know a method of doing this or know a program, app that could do this, or could have use of this your self, and decide that you want to create this. I am imagining that most here are programmers, and I am not. I can not expect any thing, I can only hope. I am a elektrician, mecanic and tecknishian, with a bit of dyslexia. So I basically know I can’t do this.
-
@Jacob-Wiqvist said in Sort Lines acording to another document?:
After that I can run the Compare or ComparePlus and see what numbers that differs
So is your intention to sort one file the same as another file so you can use the Compare plugin to identify lines/numbers that are missing. Because if that is the real reason, there is very likely a better way of achieving that.
Terry
-
Sor of.
I wan’t to sort lines that are named the same as another file that have the same names but not the same numbers after the name.
I can’t be more clear than this I think.
-
@Terry-R said in Sort Lines acording to another document?:
@Jacob-Wiqvist said in Sort Lines acording to another document?:
After that I can run the Compare or ComparePlus and see what numbers that differs
So is your intention to sort one file the same as another file so you can use the Compare plugin to identify lines/numbers that are missing. Because if that is the real reason, there is very likely a better way of achieving that.
Terry
No the line number are not interesting at all, only the parameter after the “line description.
But I any way want the lines in one file match another file.
-
I tried to apply this:
menu option Edit -> Line operations -> Sort lines lexicographicallyTo bothe files and then apply compare.
But this did not work as desired.
The best thing is if I could sort the lines the same as the second document, and select how many letters that should match in the line to move it or something.
Maybe I am thinking wrong, how to do it.
-
@Jacob-Wiqvist said in Sort Lines acording to another document?:
menu option Edit -> Line operations -> Sort lines lexicographically
To bothe files and then apply compare.
But this did not work as desired.Can you show an example of that “not working as desired”?
It may be that there’s an option on the Compare Plus plugin you can change (or maybe a feature that exists in Compare Plus that didn’t exist in the original Compare plugin – I know the Compare Plus is better at aligning things than the original Compare was)
file1:
six = 6 four = 4 two = 2 seven = 7 eight = 8
file2:
one = 0.5 + 0.25 + 0.125 + 0.0625 + ... two = 4^0.5 four = two + two six = (sticks =~ s/t|(cks)/(?1x)/) seven = sqrt(fortynine) thirtysix = six squared
sorted and compared:
That highlights the exact differences as I would expect. (And that’s with the old Compare plugin) (Okay, technically, I sorted then “removed blank lines” in both files) -
@PeterJones said in Sort Lines acording to another document?:
@Jacob-Wiqvist said in Sort Lines acording to another document?:
menu option Edit -> Line operations -> Sort lines lexicographically
To bothe files and then apply compare.
But this did not work as desired.Can you show an example of that “not working as desired”?
It may be that there’s an option on the Compare Plus plugin you can change (or maybe a feature that exists in Compare Plus that didn’t exist in the original Compare plugin – I know the Compare Plus is better at aligning things than the original Compare was)
file1:
six = 6 four = 4 two = 2 seven = 7 eight = 8
file2:
one = 0.5 + 0.25 + 0.125 + 0.0625 + ... two = 4^0.5 four = two + two six = (sticks =~ s/t|(cks)/(?1x)/) seven = sqrt(fortynine) thirtysix = six squared
sorted and compared:
That highlights the exact differences as I would expect. (And that’s with the old Compare plugin) (Okay, technically, I sorted then “removed blank lines” in both files)That is what I wan’t to do automatically!
If Ther is a program, app , plugin, webpage or anything that can do that I am interested.
-
@Jacob-Wiqvist said in Sort Lines acording to another document?:
That is what I wan’t to do automatically
There is no plugin that will save you those four menu operations into one. However, I think you can record a macro to do it (on my phone, so cannot test it for you). But sort, remove blank lines, and I believe toggle active view are all macro recordable
-
@PeterJones said in Sort Lines acording to another document?:
@Jacob-Wiqvist said in Sort Lines acording to another document?:
That is what I wan’t to do automatically
There is no plugin that will save you those four menu operations into one. However, I think you can record a macro to do it (on my phone, so cannot test it for you). But sort, remove blank lines, and I believe toggle active view are all macro recordable
What four menu options?
Did I miss something?
-
@Jacob-Wiqvist said in Sort Lines acording to another document?:
What four menu options?
Did I miss something?I had hoped that my image headers saying “sorted”, and then my later paragraph saying “I sorted then ‘‘removed blank lines’’ in both files” would have communicated that. But to be more explicit:
The steps I took in my screenshots on Saturday were:
- Put file1 in view 1 and file2 in view 2; have File 1 active
- Edit > Line Operations > Sort Lexicographically Ascending
- Edit > Line Operations > Remove Empty Lines
- Use F8 (View > Focus on Another View) to make file2 active
- Edit > Line Operations > Sort Lexicographically Ascending
- Edit > Line Operations > Remove Empty Lines
- Plugins > Compare (or Compare Plus) > Compare
The “four menu options” I meant were steps 2,3, 5,6.
When I tried it out today (now that I’m back on a PC), I found that the View>Focus (F8) is not macro-recordable, though it is macro-playable. I also found that ComparePlus wanted a blank line at the start of both to help it align (even though the older Compare didn’t), so I’ll include it below:
The following macro will Sort the active view, Remove Blank Lines in the active view, then add a single blank line to the beginning of that view. Then it will toggle views. Then it will do those three steps on the second view. Once there, it should be ready for you to use Plugins > Compare Plus > Compare.
<Macro name="SortAndTrimBothViews" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="2" message="0" wParam="42059" lParam="0" sParam="" /> <Action type="2" message="0" wParam="42055" lParam="0" sParam="" /> <Action type="0" message="2316" wParam="0" lParam="0" sParam="" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="
" /> <Action type="0" message="2316" wParam="0" lParam="0" sParam="" /> <Action type="2" message="0" wParam="44072" lParam="0" sParam="" /> <Action type="2" message="0" wParam="42059" lParam="0" sParam="" /> <Action type="2" message="0" wParam="42055" lParam="0" sParam="" /> <Action type="0" message="2316" wParam="0" lParam="0" sParam="" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="
" /> <Action type="0" message="2316" wParam="0" lParam="0" sParam="" /> </Macro>
- Open
%AppData%\Notepad++\shortcuts.xml
- Paste in the macro into the
<Macros>
section - Save
shortcuts.xml
- Completely exit Notepad++
- Run Notepad++
From now on, Macros > SortAndTrimBothViews will be in your macros menu (and you can use Macro > Modify Shortcut/Delete Macro to add a keyboard shortcut to that macro, if you want). So then the steps for you would be
- Put file1 in view 1 (left)
- Put file2 in view 2 (right)
- Run Macros > SortAndTrimBothViews
- Run Plugins > Compare Plus > Compare
-
Extreamly bigg thank you for the efort, I see you have put some time in to this.
Unfortunatly it did not work.
Her are the 2 exampels from the files I want the lines in"model1" to be orderd after document “model2”
[AERODYNAMICS] drag_coef_zero_lift = 0.0205078124 ; The zero lift drag polar drag_coef_flaps = 0.11865233 ; Cd_df Drag Coefficient - Flaps drag_coef_gear = 0.03466797 ; CDg (Drag Coefficient - Landing Gear) drag_coef_spoilers = 0.023464 ; 0.023464 Cd_ds Drag Coefficient - Spoiler drag_coef_air_spoilers = 0.0236436 lift_coef_daoa = 2.19384765 ; lift per change in angle of attack rate lift_coef_pitch_rate = -10.4453125 ; The change in lift per change in pitch rate lift_coef_delta_elevator = -0.3583984 ; The change in lift per change in elevator deflection lift_coef_horizontal_incidence = 1.89208984 ; The change in lift per change in horizontal incidence angle lift_coef_flaps = 1.36864 ; Change in lift due to flaps lift_coef_spoilers = -0.0498002 ; Change in lift due to spoilers lift_coef_air_spoilers = -0.049264 roll_moment_slip_angle = -0.081964295 ; The change in roll moment per sideslip angle(DIHEDRAL EFFECT) roll_moment_delta_aileron = -0.39990233 ; (control)The change in roll moment per change in aileron deflection roll_moment_delta_rudder = -0.04345704 ; (control)The change in roll moment per change rudder deflection roll_moment_roll_damping = -3.96386717 ; Cl_p Roll Moment - Roll Rate (Damping) roll_moment_yaw_rate = -0.1015623 ; Cl_r Roll Moment - Yaw Rate roll_moment_spoilers = 0.05522 ; The change in roll moment due to spoilers roll_moment_delta_aileron_trim_scalar = -0.00523 ; Change in roll moment due to aileron trim pitch_moment_aoa_0 = -0.11464 ; Pitch moment at zero angle - of - attack pitch_moment_daoa = 0.283220 ; The change in pitch moment per change in angle of attack pitch_moment_delta_elevator = -0.7875936 ; The change in pitch moment per change in elevator deflection pitch_moment_horizontal_incidence = 4.421377 ; The change in pitch moment per change in horizontal incidence angle pitch_moment_pitch_damping = -1464.564 ; The change in pitch moment per change in pitch rate(PRIMARY PITCH STABILITY FACTOR). deg/s pitch_moment_delta_elevator_propwash = -3.64012 ; Cm_dT Pitch Moment - Thrust pitch_moment_pitch_propwash = 0.0 ; Cmq_dT Pitch Damping - Thrust pitch_moment_delta_trim = -3.764022 ; The change in pitch moment per change in trim pitch_moment_flaps = 0.01643210 ; The pitch moment due to flaps pitch_moment_gear = -0.00262042 ; The pitch moment due to gear pitch_moment_spoilers = -0.0595002 ; The pitch moment due to spoilers yaw_moment_slip_angle = 0.288571 ; The change in yaw moment per change sideslip angle(WEATHER VANING EFFECT) yaw_moment_delta_aileron = -0.007324217 ; (adverse yaw) The change in yaw moment per change aileron deflection yaw_moment_delta_rudder = 0.04886719 ; (control)The change in yaw moment per change in rudder deflection PRIMARY YAW POWER FACTOR yaw_moment_delta_rudder_propwash = 0.0 ; (control) yaw_moment_yaw_propwash = 0.0 ; (damping) yaw_moment_roll = 0.0678712 ; (adverse yaw) The change in yaw moment per change in roll rate deg/s yaw_moment_yaw_damping = -0.896484374 ; (damping)The change in yaw moment per change in yaw rate(PRIMARY YAW STABILITY FACTOR deg/s) yaw_moment_delta_rudder_trim_scalar = 1.123621 ; Change in yaw moment due to rudder trim side_force_slip_angle = -0.1330859377 ; (yaw angle) The change in side force per change in side slip angle side_force_delta_rudder = 0.33150390614 ; The change in side force per change in rudder deflection side_force_roll_rate = 0.089062362 ; (roll velocity) The change in side force per change in roll rate side_force_yaw_rate = 0.099541314 ; (yaw velocity) The change in side force per change in yaw rate
[aerodynamics] // elevator_lift_coef = 1.62 // EXP WAS 1.80 rudder_lift_coef = 1.725 // EXP WAS 1.25 aileron_up_drag_coef = 0.45 // EXP WAS 0.5 aileron_down_drag_coef = 0.90 // EXP WAS 1.0 fuselage_lateral_cx = 0.36 // EXP compute_aero_center=0 aero_center_lift=-8.39376 presspt_fwd_Alpha0_pMAC=0 presspt_fwd_AlphaStall_pMAC=0 presspt_fwd_AlphaHiStall_pMAC=-0.25 // LIFT COEF lift_coef_at_drag_zero_flaps=0 lift_coef_at_drag_zero=0 lift_coef_delta_elevator=-0.358398 lift_coef_horizontal_incidence=1.891602 lift_coef_flaps=1.37843 lift_coef_spoilers=-0.05 lift_coef_air_spoilers=-0.05 // DRAG COEF drag_coef_zero_lift=0.018066 drag_coef_flaps=0.117188 drag_coef_gear=0.029785 drag_coef_spoilers=0.02392 drag_coef_air_spoilers=0.02392 // side_force_delta_rudder=-0.1743 side_force_roll_rate=0.014648 side_force_yaw_rate=0 side_force_slip_angle=-1.24512 // -0.124512 pitch_moment_delta_elevator=-1.391602 pitch_moment_delta_trim=-3.525 pitch_moment_pitch_damping=-178.222656 pitch_moment_aoa_0=0.014648 pitch_moment_daoa=9.375977 pitch_moment_horizontal_incidence=4.421875 pitch_moment_flaps=0.0155 pitch_moment_gear=-0.0025 pitch_moment_spoilers=0.005 pitch_moment_delta_elevator_propwash=0 pitch_moment_pitch_propwash=0 lift_coef_pitch_rate=-10.449219 lift_coef_daoa=2.195801 roll_moment_delta_aileron=-0.401855 roll_moment_roll_damping=-2.127441 roll_moment_yaw_rate=-0.019531 roll_moment_delta_rudder=-0.043945 roll_moment_slip_angle=0.072266 roll_moment_spoilers=0.055 roll_moment_delta_aileron_trim_scalar=-0.039247 yaw_moment_delta_rudder_trim_scalar=0.017896 yaw_moment_roll=0.036621 yaw_moment_slip_angle=0.172852 yaw_moment_delta_rudder=0.230469 yaw_moment_delta_aileron=-0.009766 yaw_moment_yaw_damping=-1.171875 yaw_moment_delta_rudder_propwash=0 yaw_moment_yaw_propwash=0
They are totaly diferent but at the same time the same type of parameters.
I changed the parameters, copied wrong. It is only a few lines of about 400 lines.
-
@Jacob-Wiqvist said in Sort Lines acording to another document?:
They are totaly diferent but at the same time the same type of parameters.
Just how in the world do you expect to sort model1 according to the order in model2 if model2 and model1 contain no parameters that are the same?
Sorry, I cannot help you. Maybe someone else can.
-
It is considered rude to edit a post after you have received a reply. Because your data now does match, it makes it look like I was wrong when I said your data doesn’t match; but two hours ago, it didn’t match. Now it does.
-----
If I take the first half of your edited post, and sort it as file1 on the left, and the second half of your edited post, and sort it as file2 on the right, then run ComparePlus > Compare, it properly lines things up. The same would have happened if you used my macro.
sorted:
compared:
PEBCAK