Vi - insert a tab between words? | 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 - insert a tab between words?

UNIX for Dummies Questions & Answers


Tags
space, tabs, vi

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 12-11-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 17 September 2014, 6:33 PM EDT
Location: Galactic Empire
Posts: 3,382
Thanks: 234
Thanked 1,206 Times in 1,133 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 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 12-11-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 17 September 2014, 6:33 PM EDT
Location: Galactic Empire
Posts: 3,382
Thanks: 234
Thanked 1,206 Times in 1,133 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 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 12-11-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 15 July 2014, 11:14 AM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
try:

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

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
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:37 PM.