Match keyword on string and substitute under vi


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match keyword on string and substitute under vi
# 1  
Old 04-25-2008
Match keyword on string and substitute under vi

Hi guys,

with sed when I need to make a substitution inside a line containing a specific keyword, I usually use:

sed '/keyword/ s/cat/dog/g'

This will substitute "cat" with "dog" on those lines containing "keyword". Now I want to use this inside vi, for several reason that I cannot explain, but I don't seem to find the right syntax.

Has any of you shell wizards the proper syntax to use? Thanks!
# 2  
Old 04-25-2008
The corresponding command in vi is:

Code:
:g/keyword/s/cat/dog/g

Regards
# 3  
Old 04-25-2008
Quote:
Originally Posted by Franklin52
The corresponding command in vi is:

Code:
:g/keyword/s/cat/dog/g

Regards
Thanks a lot, it worked like a charm! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

How to block domains that match a keyword?

I want to know, for internet access, if there is an easy way to filter domain names, on your Linux box, that match certain key(s) without using squid. For example, if you want to block example.com you add the following lines in your /etc/hosts file: 0.0.0.0 www.example.com 0.0.0.0 example.com... (2 Replies)
Discussion started by: milhan
2 Replies

2. Shell Programming and Scripting

awk to match keyword and return matches and unique fields

Trying to use awk to find a keyword and return the matches in the row, but also $1 and $2, which are the unique id's, but they only appear once. Thank you :). file name 31 Index Chromosomal Position Gene Inheritance 122 2106725 TSC2 AD 124 2115481 TSC2 AD 121 2105400 TSC2 AD... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Substitute first occurrence of keyword if occurrence between two other keywords

Assume a string that contains one or multiple occurrences of three different keywords (abbreviated as "kw"). I would like to replace kw2 with some other string, say "qux". Specifically, I would like to replace that occurrence of kw2 that is the first one that is preceded by kw1 somewhere in the... (4 Replies)
Discussion started by: M Gruenstaeudl
4 Replies

4. Shell Programming and Scripting

Substitute keyword in html address

I have data that looks like the below: PXL-A0000005 DTE3504500000005 PXL-A0000007 DTE3504500000007 PXL-A0000014 DTE3504500000014 PXL-A0000015 DTE3504500000015 PXL-A0000016 DTE3504500000016 What I am trying to do is use the value in $1 and substitute it in catno=....&storage . I do... (2 Replies)
Discussion started by: cmccabe
2 Replies

5. UNIX for Dummies Questions & Answers

How to substitute for the partial match?

Hi I have a question and hope I can get answer here. Thank you in advance. I have two files: file1: aa X bb Y cc Z file2: cc A bb B dd C aa D bb E If the 1st column match in both file1 and file2, the 2nd column in file2 will be replaced by the 2nd column in file1. If there is no... (2 Replies)
Discussion started by: yuejian
2 Replies

6. UNIX for Dummies Questions & Answers

Partial match in two files then substitute

Hi, I was trying to figure this out but failed so I hope someone here can help me, thank you in advance. I have two files. file1: aa M bb N cc O dd P ee Q file2: aa A_87_P254063 cc A_87_P016532 bb A_87_P104793 dd A_87_P055331 ee A_87_P059706 aa A_87_P071636 ee A_87_P028302... (2 Replies)
Discussion started by: yuejian
2 Replies

7. Shell Programming and Scripting

Remove not only the duplicate string but also the keyword of the string in Perl

Hi Perl users, I have another problem with text processing in Perl. I have a file below: Linux Unix Linux Windows SUN MACOS SUN SUN HP-AUX I want the result below: Unix Windows SUN MACOS HP-AUX so the duplicate string will be removed and also the keyword of the string on... (2 Replies)
Discussion started by: askari
2 Replies

8. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

9. UNIX for Dummies Questions & Answers

Find and substitute a string

Hi, I started exploring unix recently. Now i have got a requirement like i have a input file where i am having some strings line by line (One string Might be single line or multiple lines). Now i need find these strings in another file and if its found i have to replace it with another string... (2 Replies)
Discussion started by: Sivajee
2 Replies

10. Shell Programming and Scripting

To substitute a string in a line to another string

Suppose, d=ABC*.BGH.LKJ Now I want to replace 'DEFGHIJ' instead of '*.B' and store the value in d. Any Idea? Can we use sed here? The outout should be like this: d=ABCDEFGHIJGH.LKJ Please help.. (4 Replies)
Discussion started by: Niroj
4 Replies
Login or Register to Ask a Question