I wonder is there a way to REVERSE THE LINE ORDER for instance
from this:
Line 5
Line 4
Line 3
Line 2
Line 1
to:
Line 1
Line 2
Line 3
Line 4
Line 5
A bit late, but yes, there is: Select the amount of lines you want to reverse and click
Edit > Permute Lines > Reverse.
Related
I have a text file which looks like this:
1 1 1 \n
1 1 2 \n
1 1 3 \n
1 2 1 \n
1 2 2 \n
1 2 3 \n
1 3 1 \n
1 3 2 \n
I want to save each line in a new text file. I've developed the code already but this saves each line at the beginning of the text file.
I want to save each line of the master text file separately in a new file but at a specific line and column.
For example 1 1 1 should be in a new file [a1.text] at line 5 and colmn 10. 1 1 2 should be in a new file [a2.text] at line 4 column 10.
How can edit the code? |T tried different methods, using seek, writelines, insert but I am confused because maybe I am mixing pathlib with os.
I also have tried seek, insert. but may be i am not doing it write.
from pathlib import *
z= Path ('Desktop/pythonfiles/a.DATA').read_text().splitlines ()
for i in z:
print (i , file= open ('c:/Users/Muhammad Ali/Desktop/python files/'+i+'.DATA', 'w'))
Result:
1 1 1 saving in a newfile (a1.text) at Line 5, column 20 1 1 2 saving
in a newfile (a2.text) at line 6, column 20
You can directly read the text file as liens using readlines() method then loop over the lines printing each line in a new file while formatting the file name with an incrementing counter, as follows:
data = open('source.txt','r').readlines()
file_num = 1
for line in data:
open('a{}.txt'.format(file_num),'w').write(line)
file_num+=1
Suppose I have something like this:
line 1 with text
line 2 with text
line 3 with text
line 4 with text
I want to unindent all of these lines to the beginning, like this:
line 1 with text
line 2 with text
line 3 with text
line 4 with text
Shift + V < gives me ONE level of un-indentation. How can I get them all to the beginning? Sorry, I'm having trouble phrasing this...
There are two different ways you could do this:
Visually select all of the lines, press <, and then press . as many times as you need until there is no indent left. Or if there are a specific number of lines you would like this on, you could do something like
5<< (unindent 5 lines)
<j (unindent this line and the next)
<ip (unindent inside this paragraph)
followed by as many . as you need.
Select all of the lines, and then type either :norm d^ or :s/^\s*
Also, Shift-V + V + < is basically the same as <<.
I want to write an AppleScript that will delete the first 10 lines of a string.
set text to "Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
Line 13"
So the result of variable text would be:
Line 11
Line 12
Line 13
Thanks.
Editor's note: The question's massive input/output affected readability. Deleting the first 10 will suffice. You should be able to extrapolate the solution to 30 lines.
#! /usr/bin/env bash
sed '1,10d'
I'm using the following command to match the following line in a file:
cat file.txt | grep -A 1 'match' > output.txt
This allows me to get the line after 'match' is found in the following file:
match
random text line 1
match
match
match
random text line 2
match
random text line 3
match
match
random text line 4
match
random text line 5
match
random text line 6
match
random text line 7
match
random text line 8
match
match
random text line 9
However, I need to return only the lines after 2 or more consecutive 'match' lines. In this case the output would be:
random text line 2
random text line 4
random text line 9
I have tried using a combination of grep -A 2 'match' | grep -A 1 'match' but it doesn't work as it's redundant. I'm stuck on how to match only if there are two consecutive lines. I'm open to using awk or sed for matching too if it's more efficient. Any direction would be greatly appreciated.
grep stands for g/re/p i.e. it's for Globally finding a Regular Expression and Printing the result, that is all. That is not all that you are trying to do so therefore grep would be the wrong tool to try to use. For general purpose text manipulation the standard tool to use is awk:
$ awk '/match/{c++;next} c>1; {c=0}' file
random text line 2
random text line 4
random text line 9
I saw the bottom jump list in Vim (ju in normal mode) could be in 2 different forms as below. The current pos (> sign) points to empty line in the first output, but not the case for the second output. I am wondering how to enter such state of jump list separately and what's the effect on navigation?
2 1 2 Some line in file
1 2 2 Another line in file
>
2 1 2 Some line in file
> 1 2 2 Another line in file
The > shows your current position in the jumplist.
The empty line means that the cursor is currently not at a position in the jumplist.
No empty line means that you jumped to some position in the list.