global substitution in VI | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

global substitution in VI

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-09-2008
OLweiser OLweiser is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 19 February 2008, 11:02 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
global substitution in VI

Hi All,
I'm trying to add a carriage return to the end of my lines in a text file using substitution, but I havent found a way as yet.

Can anyone help?

something along the lines of:
:%s/<^A/^M/g obviously, this doesnt work.

Many thanks.
Sponsored Links
    #2  
Old 02-09-2008
ennstate's Avatar
ennstate ennstate is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 10 September 2012, 1:18 PM EDT
Location: Stockholm
Posts: 230
Thanks: 1
Thanked 4 Times in 4 Posts
Quote:
Originally Posted by OLweiser View Post
Hi All,
I'm trying to add a carriage return to the end of my lines in a text file using substitution, but I havent found a way as yet.

Can anyone help?

something along the lines of:
:%s/<^A/^M/g obviously, this doesnt work.

Many thanks.
I doubt that the pattern you are matching.Did you try,

Code:
:%s/$/^M/g

Where,^M - Ctrl-v+Ctrl-M

Thanks
Nagarajan G
Sponsored Links
    #3  
Old 02-09-2008
OLweiser OLweiser is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 19 February 2008, 11:02 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Where,^M - Ctrl-v+Ctrl-M

I dont fully understand what your suggesting here, can you expand on what key strokes need to be input?

thanks, Ollie
    #4  
Old 02-09-2008
ennstate's Avatar
ennstate ennstate is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 10 September 2012, 1:18 PM EDT
Location: Stockholm
Posts: 230
Thanks: 1
Thanked 4 Times in 4 Posts
I meant the keystrokes for getting ^M is ( you have to Hold Ctrl key and press v and then M )
Thanks
Nagarajan G
Sponsored Links
    #5  
Old 02-09-2008
OLweiser OLweiser is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 19 February 2008, 11:02 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
thanks, unfortunatley that doesnt work. Although it sends a carriage return, it doesnt translate when opened in a text file and still shows each line continuously.
I know if I can get a true ^M at the end of each line it will work..
any ideas?
Sponsored Links
    #6  
Old 02-09-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
 
Join Date: May 2006
Last Activity: 4 May 2012, 3:37 PM EDT
Location: Tau Ceti V
Posts: 558
Thanks: 0
Thanked 7 Times in 6 Posts
If you open a file in vi and it is a continuous line, it means there are no carriage returns in your file (or at least any that vi understands), so s/$/^M/ will only put a ^M at the very end of the one big line. vi has no idea when your lines are supposed to end, how do you expect vi to recognize that?
I have no idea how you are trying to view this file, I'm guessing you are trying to view it in a windows app because you are trying to append ^M, and that is how vi "interprets" the DOS carriage return when vi opens a text file written in windows, but it doesn't mean that your windows app is going to interpret ^M as a carriage return, it is just going to see it as two characters: ^ and M.

Last edited by System Shock; 02-09-2008 at 01:20 PM..
Sponsored Links
    #7  
Old 02-11-2008
OLweiser OLweiser is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 19 February 2008, 11:02 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Following on from this and still using substitution, is it possible to search and replace a field (column) rather than just a character/s?

I need a way of replacing a TAB between 2 fields with a single space.
i.e.
SURNAME FORENAME
to:
SURNAME FORENAME

Any ideas?
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
How to identify a global or non-global Solaris server? kalpeer Solaris 25 04-12-2010 01:25 PM
How to see global hostname by logging in non global zones? girish.batra Solaris 2 03-28-2010 02:58 AM
How to access ENV variables of non global zones in global zone??? vijaysachin Solaris 1 02-08-2010 08:40 AM
How can we copy a directory from Global to Non-global zone? vijaysachin Solaris 8 11-18-2009 07:41 AM
sed global substitution for ' character borderblaster Shell Programming and Scripting 1 12-21-2008 03:34 PM



All times are GMT -4. The time now is 06:50 PM.