To remove whitespace characters, such as spaces and/or tabs from
a line while editing a file in the vi and
Vim text editor you can use a
regular expression (regexp) that incorporates
(lowercase letter "s"), which respresents a white space character. E.g.,
supposing the lines below appear in a file:
450 SN/GN Tech Edit Delete ACE Edit Delete ADO Edit Delete AGO Edit Delete AGS Edit Delete AIM Edit Delete ASF Edit Delete
I could hit the
colon key and type
s/\s*Edit Delete// to
delete the white space after the project name that appears at the
beginning of the line and the "Edit Delete" at the end of the line, so that
only the project name remains. To perform the substitution for all lines,
I could use
1,$ s/\s*Edit Delete//.
1,$ represents every line from the 1st to the last
1,$ s/old_pattern/new_pattern/ would indicate
that a substitution is to be performed on every line with new_pattern
replacing old_pattern on each line.
\s represents any whitespace character and the
after it indicates to look for zero or more occurrences of any whitespace
s/\s*Edit Delete// indicates to delete white
space characters followed by the words
I could also use
any non-alphanumeric character.
Lesson 9: All this
RegexOne - Learn Regular Expressions with simple, interactive exercises.