LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2008, 07:53 AM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
Substitution of data and VI


I have this file:

PHP Code:
192.168.1.1  v0
192.168.1.2  v0 
192.168.1.3  v1 
192.168.1.4  v1
192.168.1.5  v1
192.168.1.6  v2
192.168.1.7  v2 
I want to substitute the v0-2 with NAM0-2 to get:

PHP Code:

192.168.1.1  NAM0
192.168.1.2  NAM0 
192.168.1.3  NAM1 
192.168.1.4  NAM1
192.168.1.5  NAM1
192.168.1.6  NAM2
192.168.1.7  NAM2 
How can I do so with VI

PHP Code:
/s/v0/NAM0/
It doesnt work. thanks
 
Old 01-17-2008, 08:00 AM   #2
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Never mind I had a brain fart. It happens every now and then. The anwser to my problem was resolved by a simple google search:

PHP Code:
1,$s/thisvalue/withthis/
Will do the trick. Sorry
 
Old 01-17-2008, 05:11 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
FYI:
1,$
means line 1 to last line; equiv to
%
as in
%s/old/new/g
where g is every occurence on each line, otherwise it's just the first occurence on each line (in your case that's enough, you only have one per line).

HTH
 
Old 01-18-2008, 05:09 AM   #4
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Does that mean I could have used

PHP Code:
%s/old/new/
instead of

PHP Code:
1,$s/thisvalue/withthis/
?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
substitution ovince Programming 3 04-28-2007 05:35 AM
Substitution in Perl rigel_kent Programming 4 06-02-2006 10:11 AM
command substitution: ^ rhxk Linux - General 2 04-06-2006 09:51 AM
process substitution jk3us Linux - Software 1 12-02-2004 04:34 PM
Is there any substitution to Ghost? Swift&Smart Linux - Software 12 06-22-2004 05:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration