grnmachine
asked on
How to delete words using pattern in vi
Hi,
I am trying to find all words in my file that are 4 characters long and start with a B or b and delete those words. I am trying to break down the regular expression into parts and build onto it as I get things working. So far, I am just trying to delete words starting with a B using this vi command: g/^B/dw, but I get a 'Not an editor command: dw' error. Could someone point me in the right direction? thanks.
I am trying to find all words in my file that are 4 characters long and start with a B or b and delete those words. I am trying to break down the regular expression into parts and build onto it as I get things working. So far, I am just trying to delete words starting with a B using this vi command: g/^B/dw, but I get a 'Not an editor command: dw' error. Could someone point me in the right direction? thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The command just seems to highlight the whole line that has four letter words starting with a B or b. I would like to have the command find four letter words and delete only those words starting with a B or b. I'm I entering the command incorrectly? Could you break down what each item in the expression means? I am just learning vi/regular expressions and its still a bit confusing. Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Hatrix76
Okay, let me try it out and I will get back to you. Thanks.
Okay, let me try it out and I will get back to you. Thanks.
The alphabet s is for search/substitute
\< means starting of word
[Bb] means B or b
\p means printable characters
\{3\} means as it is followed by \p match 3 printable characters after B or b
// means substitute with nothing.
g means global in other words the entire file.
\< means starting of word
[Bb] means B or b
\p means printable characters
\{3\} means as it is followed by \p match 3 printable characters after B or b
// means substitute with nothing.
g means global in other words the entire file.
Hi,
For deleting a particular word in a file,Please use the following command.
:%s/\<mohan\>.\{0}//
Note:here Mohan is the word for delete in the file.
Cheers,
Mohan Sahu
For deleting a particular word in a file,Please use the following command.
:%s/\<mohan\>.\{0}//
Note:here Mohan is the word for delete in the file.
Cheers,
Mohan Sahu
:s/\<[Bb]\p\+//g