vi Search for text, Replace with <CR> or control character. | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

vi Search for text, Replace with <CR> or control character.

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-20-2009
omega949 omega949 is offline
Registered User
 
Join Date: May 2009
Last Activity: 26 May 2009, 1:52 PM EDT
Location: Aliso Viejo, CA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
vi Search for text, Replace with <CR> or control character.

Greetings,

Using vi, how can I change the following text:
-I/myviews/nexus_7400rel/vobs/nexus/platforms/97400/include -I/myviews/nexus_7400rel/vobs/nexus/modules/i2c/7400/include -I/myviews/nexus_7400rel/vobs/nexus/modules/surface/7400/include

Into this:
/myviews/nexus_7400rel/vobs/nexus/platforms/97400/include
/myviews/nexus_7400rel/vobs/nexus/modules/i2c/7400/include
/myviews/nexus_7400rel/vobs/nexus/modules/surface/7400/include

The first text is a contiguous string with spaces and "-I" separating the lines of include paths (yes, this is from a "C" makefile output).

I want to search for all the occurances of " -I", and replace with a carriage return (or linefeed) using vi. This is for vi on a Linux system.

The search portion is easy: :g/ -I/s// (what goes here?)/g

It's the "what goes here?" part that I need help with.

Any answers or alternative solutions would be greatly appreciated.

Omega949
Sponsored Links
    #2  
Old 05-20-2009
Padow Padow is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 10 July 2014, 2:26 PM EDT
Location: Maryland
Posts: 221
Thanks: 2
Thanked 1 Time in 1 Post

Code:
:1,$s/-I/\n/g

Sponsored Links
    #3  
Old 05-20-2009
omega949 omega949 is offline
Registered User
 
Join Date: May 2009
Last Activity: 26 May 2009, 1:52 PM EDT
Location: Aliso Viejo, CA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Padow,

Unfortunately, using your syntax causes each instance of " -I" to be replace with "^@" as in:

^@/myviews/nexus_7400rel/vobs/nexus/platforms/97400/include ^@/myviews/nexus_7400rel/vobs/nexus/modules/i2c/7400/include ^@/myviews/nexus_7400rel/vobs/nexus/modules/surface/7400/include

Any other ideas?

Omega949
    #4  
Old 05-20-2009
omega949 omega949 is offline
Registered User
 
Join Date: May 2009
Last Activity: 26 May 2009, 1:52 PM EDT
Location: Aliso Viejo, CA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Found the fix (aka: solution)

Thanks (again) to Padow, a slight change to his syntax solved the problem. Here is the syntax that worked:

:1,$s/ -I/\r/g

Note that I included a space in the seach-for text " -I". This allowed for the extra space to be removed so each line starts at the beginning.

Cheers!

Omega949
Sponsored Links
    #5  
Old 05-21-2009
zedex zedex is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 3 June 2014, 8:04 AM EDT
Location: Mumbai, India
Posts: 185
Thanks: 6
Thanked 5 Times in 5 Posts
Quote:
Code:
:1,$s/ -I/\r/g


Code:
you can replace 1,$ by % - indicates replace on all lines 
%s/-I/\r/g

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
search and replace a text in a file goutam_igate Shell Programming and Scripting 5 04-27-2009 07:03 AM
Need to search and replace based on character count vijaykrc Shell Programming and Scripting 3 02-19-2009 01:48 PM
How to replace all entries of comma in text file by space or other character prashant43 Shell Programming and Scripting 4 08-30-2008 01:53 AM
search and replace a specific text in text file? santosham UNIX for Dummies Questions & Answers 4 06-25-2008 06:53 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM



All times are GMT -4. The time now is 06:34 AM.