Reputation: 10119
I have a file "file.txt" in which some rows begins with numbers.
E.g. file.txt:
1 bla bla 390
23 foo foo 100
# bar bar
some word
45 junk
Is there an easy and fast way to delete the numbers (and the space) from all the lines that start with a number, while deleting only the space from the others?
I would like a command so that the file then looks like:
bla bla 390
foo foo 100
# bar bar
some word
junk
Upvotes: 7
Views: 7090
Reputation: 2811
this regular expression works in geany, just use replace in document
^([\d]+ +)|^( +)
it gives your desired output for the input below
1 bla bla 390
23 foo foo 100
# bar bar
some word
45 junk
Upvotes: 0
Reputation: 15917
You can use the command editor line:
:%s/^\d*//
This uses the global search %s
to find any line that begins with a digit \d*
and replace it with nothing //
.
Additionally, if you need to remove the extra space after the number as well:
:%s/^\d* //
Upvotes: 13