Cut the first line of a file and paste it in another file.
-
Hello,
I’m dealing with two files, where i’m mixing data and adding lines from file 1 to file 2.File1 consists of 1000s single lines
line 1 line 2 line 3 etc
File 2 contains random data
line 1 copy line 1 from file 1 line 2 copy line 2 from file 1 line 3 copy line 2 from file 1
All I’m doing now is opening both file in the application and manually copying and pasting the lines. I know that notepad++ can do much more… is it possible to make this task a bit easier for me?
Thanks.
-
@Ahmed-Obaid said in Cut the first line of a file and paste it in another file.:
is it possible to make this task a bit easier for me?
Indeed there is a faster method. record a macro that emulates the keystrokes you are using and save it. Then you can run the macro and it will repeat those steps without fail everytime.
So we have:
Ctrl-PageDown - next tab
Ctrl-PageUp - previous tab
Ctrl-Home - go to start of file
Shift-Down Arrow - highlights current line including line feed/carriage return
Please understand that some shortcuts may have been altered in your Notepad++ installation, in which case use those you have assigned for each of the tasks.- So you would make sure you are in the “source file” before starting the recording.
- Ctrl-Home to get to first character position in file
- Shift-Down Arrow to select first line
- Ctrl-C copies selected line
- Ctrl-PageDown to select next tab, in this case the “recipient file”
- Ctrl-Home to position cursor in first position
- Ctrl-V to insert (from clipboard)
- Optionally Ctrl-PageUp to move focus back to the “source file”.
This is the macro you see below. You could add that to your shortcuts.xml (generally under %AppData% folder, and then under Notepad++) file however ONLY do this in a session by itself if using Notepad++, or do it with another editor when Notepad++ isn’t running.
<Macro name="tab1 line 1 to tab2 insert 1st line" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2316" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2301" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2178" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2422" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2325" wParam="0" lParam="0" sParam="" /> <Action type="2" message="0" wParam="44095" lParam="0" sParam="" /> <Action type="0" message="2316" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2179" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2422" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2325" wParam="0" lParam="0" sParam="" /> <Action type="2" message="0" wParam="44096" lParam="0" sParam="" /> </Macro>
Terry
PS note I used the copy as that’s what your post suggested, although the title of your post suggested cut, in which case after step 4, insert a “delete” keystroke.
-
@Ahmed-Obaid said in Cut the first line of a file and paste it in another file.:
know that notepad++ can do much more… is it possible to make this task a bit easier for me?
I should add that my solution was to copy line 1 from tab 1 and insert into line 1 of tab 2. Of course your example does show it being inserted into different locations which means the macro would need to select the appropriate line before pasting. that’s a bit more difficult depending on how you do it. Likely you would have the macro perform the first few steps only (1-5). Then you would position the cursor at the right location in tab 2 and press the Ctrl-V to insert from clipboard. Then you would need to focus back on the tab 1 file again manually.
I do see that Notepad++ seems to remember the location of the cursor in each tab, not sure if that will always happen. @PeterJones, or other seasoned NPP user, can you confirm cursor position recorded for each tab (file) opened, and will be used when focus back on it? If you could trust that then you would start in tab 2 (recipient file) first, position cursor and then start the macro. it would change to tab 1, proceed with home, select, copy, back to tab 2 and insert, then stop.
Terry
-
@Terry-R said in Cut the first line of a file and paste it in another file.:
I do see that Notepad++ seems to remember the location of the cursor in each tab, not sure if that will always happen.
In the Notepad++ manual (online) it does state:
The session file stores the paths of the open files, the active file (and which view, see the section about Multi-View),
the current selection and position in the file
, the current bookmarks (see Bookmarks) and the current language (see the section about Languages). When you load the session, all of that information is loaded back into Notepad++.which suggests that is true. In my case I did not load a session, but this session.xml file is recording information about my tabs (files) opened.
Terry
-
@Terry-R said in Cut the first line of a file and paste it in another file.:
Indeed there is a faster method. record a macro that emulates the keystrokes you are using and save it. Then you can run the macro and it will repeat those steps without fail everytime.
You can’t believe how many clicks you’ve saved me. Thanks for your detailed answer.
That did the trick for me.