Vim help - delete words in a file or characters after pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Vim help - delete words in a file or characters after pattern
# 1  
Old 08-30-2010
Vim help - delete words in a file or characters after pattern

I have a file with words that begin with character #. Whenver that character is found that word should be deleted throughout the file. How do I do that in VIM.

e.g:

Code:
afkajfa ladfa ljafa #222222 kjafad ljl
afajkj kjlj uouu #44444 jlkj lkjl

Output should be

Code:
afkajfa ladfa ljafa  kjafad ljl
afajkj kjlj uouu jlkj lkjl


Last edited by Scott; 08-30-2010 at 07:31 PM.. Reason: Please use code tags
# 2  
Old 08-30-2010
Hi.

Try:

Code:
$ sed 's/#[^ ]* *//g' infile
afkajfa ladfa ljafa kjafad ljl 
afajkj kjlj uouu jlkj lkjl

edit: Just noticed the subject says "VIM...." Smilie, so :%s/#[^ ]* *//g'

Last edited by Scott; 08-30-2010 at 07:44 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Pattern to remove words with less than 2 characters.

Hello. I've been thinking about how to go about this. I know I'm close but still does not work. I need to remove any word in that is not at least 2 characters long. I've removed all the non-alphabetic characters already (numbers included). Here's an example: my $string = "This string is a... (4 Replies)
Discussion started by: D2K
4 Replies

2. Shell Programming and Scripting

How Not to Delete Words that matches a PATTERN

Hi, I have a test file name test.txt with its contents string 21345 qwee strinn strriin striin i need to delete all the words except the word STRING I used the command cat test.txt | sed 's/^..*$/**/g' but the output entries still contain strinn strriin striin. Plz Help me out.... (5 Replies)
Discussion started by: Ananth12
5 Replies

3. Shell Programming and Scripting

Using Sed to Delete Words in a File

This is a Nagios situation. So i have a list of servers in one file called Servers.txt And in another file called hostgroups.cfg, i want to remove each and every one of the servers in the Servers.txt file. The problem is, the script I wrote is having a problem removing the exact servers in... (5 Replies)
Discussion started by: SkySmart
5 Replies

4. UNIX for Dummies Questions & Answers

sed how to delete between two words within a file

I'm hoping someone could help me out please :) I have several .txt files with several hundred lines in each that look like this: 10241;</td><td>10241</td><td class="b">x2801;</td><td>2801</td><td>TEXT-1</td></tr> 10242;</td><td>10242</td><td... (4 Replies)
Discussion started by: martinsmith
4 Replies

5. Shell Programming and Scripting

sed delete pattern with special characters

Hi all, I have the following lines <b>A gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) <b>B gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) <b>J gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) and I would like to... (5 Replies)
Discussion started by: stinkefisch
5 Replies

6. Shell Programming and Scripting

Need to delete words in a file

Hi All, I have an input file a.txt which contains the following :: 08-08-09 1:00 PM 763763762 f00_unix1_server.txt i Just need to delete all the words which is before f Output :: f00_unix1_server.txt Thanks (4 Replies)
Discussion started by: raghav1982
4 Replies

7. Shell Programming and Scripting

How can i delete some words in every line in a file

Hi, I need help to delete a few words in every line in my file. This is how the file look like: VDC DQ 14900098,,,,157426.06849776753,786693.2919373367 10273032,,,,157525.49445429695,776574.5546672409 VDC DG ,10273033,,3er55,,149565.57096061576,801778.9379555212 AS174 892562,,,,, ... (2 Replies)
Discussion started by: andy_s
2 Replies

8. Shell Programming and Scripting

Script for pulling words of 4 to 7 characters from a file

Even just advice on where to start would be helpful. Thank You (2 Replies)
Discussion started by: Azeus
2 Replies

9. UNIX for Advanced & Expert Users

How to delete first 10 words from file

Hi, Could you please let me know, how to delete first 10 words from text files using vi? 10dw will delete it from current line, how to do it for all the lines from file? Thanks (6 Replies)
Discussion started by: sentak
6 Replies

10. UNIX for Advanced & Expert Users

dictionary words in vim

how can i get the dictionary words in vim using keyboard keys? and how can i get the current directory filename? (1 Reply)
Discussion started by: lakshmananindia
1 Replies
Login or Register to Ask a Question