Vi - insert a tab between words? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Unix/Linux 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 - insert a tab between words?

UNIX for Dummies Questions & Answers


Tags
space, tabs, vi

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-11-2012
onlinelearner02 onlinelearner02 is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 11 December 2012, 4:27 PM EST
Posts: 17
Thanks: 6
Thanked 1 Time in 1 Post
Vi - insert a tab between words?

I have several lines in a file that I want to replace a space with a tab.

For example:

111047 [tab] Julie Jones email@email.com

111047 [tab] Julie Jones [tab] email@email.com

I want to replace the space after the word "jones" with a tab.

How do I achieve that in Vi?

Please assist.

Thanks!
Sponsored Links
    #2  
Old Unix and Linux 12-11-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 27 March 2015, 10:54 AM EDT
Location: Galactic Empire
Posts: 3,401
Thanks: 240
Thanked 1,215 Times in 1,141 Posts
Run below in VI command mode:-

Code:
:%s/Jones /Jones[tab]/g

Note: press key: Tab (highlighted) after string: Jones for replacement.
Sponsored Links
    #3  
Old Unix and Linux 12-11-2012
onlinelearner02 onlinelearner02 is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 11 December 2012, 4:27 PM EST
Posts: 17
Thanks: 6
Thanked 1 Time in 1 Post
So if i have multiple lines with different names, how do I achieve that?

Thanks much!
    #4  
Old Unix and Linux 12-11-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 27 March 2015, 10:54 AM EDT
Location: Galactic Empire
Posts: 3,401
Thanks: 240
Thanked 1,215 Times in 1,141 Posts
You can use awk instead to put a tab before last column email id:-

Code:
awk ' { email=$NF; gsub(email,"\t"email,$NF); print $0 } ' input_file

Sponsored Links
    #5  
Old Unix and Linux 12-11-2012
onlinelearner02 onlinelearner02 is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 11 December 2012, 4:27 PM EST
Posts: 17
Thanks: 6
Thanked 1 Time in 1 Post
Do you know how I could also achieve this in Vi?

Thanks!
Sponsored Links
    #6  
Old Unix and Linux 12-11-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 13 January 2015, 10:34 AM EST
Location: Houston, Texas, USA
Posts: 681
Thanks: 0
Thanked 206 Times in 198 Posts
try:

Code:
:1,$s/ \([^ ]*@\)/\t\1/

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
insert LF and TAB for formatting dba_frog Shell Programming and Scripting 1 02-11-2011 09:35 AM
sed: how to insert tab? Juha Shell Programming and Scripting 2 10-29-2007 07:15 AM
How to insert tab at specified column.HELP sslr UNIX for Dummies Questions & Answers 7 09-21-2007 10:54 AM
pls help me to insert tab and formatthe file getdpg Shell Programming and Scripting 5 02-02-2006 12:35 PM
Insert TAB in echo statement sunils27 Shell Programming and Scripting 5 08-26-2005 03:36 AM



All times are GMT -4. The time now is 11:39 AM.