Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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 !!

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-11-2012
Registered User
 
Join Date: Mar 2012
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
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,250
Thanks: 147
Thanked 710 Times in 683 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
Registered User
 
Join Date: Mar 2012
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
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,250
Thanks: 147
Thanked 710 Times in 683 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
Registered User
 
Join Date: Mar 2012
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
Registered User
 
Join Date: Sep 2012
Location: Houston, Texas, USA
Posts: 571
Thanks: 0
Thanked 173 Times in 167 Posts
try:

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

Sponsored Links
Reply

Tags
space, tabs, vi

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:13 AM.