I have a text file, which lists file names in a directory (excerpt below). The item names are the f followed 3-digit numbers.
771M Jan 22 02:35 f186
1.2G Jan 22 02:35 f172
771M Jan 22 02:36 f206
771M Jan 22 02:37 f151
771M Jan 22 02:37 f029
1.2G Jan 22 02:38 f162
771M Jan 22 02:40 f168
1.2G Jan 22 02:42 f244
...
I would like to have a list of only the 3-digit numbers. Therefore, I need to repalce the previous columns by "nothing". Since the content of the previous columns is different for each line, I would use an asterisk, and the following approach seemed logic for me in VIM:
:%s/*f/
where I replace everything followed by an f by nothing.
Why doesn't this work? How do I do this in VIM?
Vim uses regex and, in regex, an asterisk is actually a quantifier.
What you want is this:
:%s/.*f/
the . character means any character, and the * means any number of .s. So, the combination .* matches essentially anything, which is what you were looking for.
Regexes are simultaneously the most useful and annoying things I have ever learned, so I would recommend getting familiar with them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With