The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-24-2009
eXPlosion eXPlosion is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 3
Sed question

I have following input:

almantas 31949 1 0 00:00:08 ? /usr/bin/pulseaudio -D --log-target=syslog
almantas 31979 12082 0 00:00:06 pts/2 bash
almantas 31991 31949 0 00:00:00 ? /usr/lib/pulseaudio/pulse/gconf-helper
almantas 32009 1 0 00:00:06 ? /usr/lib/libgconf2-4/gconfd-2
almantas 32166 31352 0 00:00:00 ? /usr/bin/seahorse-agent --execute x-session-manager

I need to replace one or more spaces with colon ":"
Syntax would be sed 's/ \+/:/g'
But i don't want to replace all spaces, just first six . I could do something like this sed 's/ \+/:/1' | sed 's/ \+/:/1' | sed 's/ \+/:/1' | sed 's/ \+/:/1' | sed 's/ \+/:/1' | sed 's/ \+/:/1'
How do i make sed repeat only 6 times? Like sed 's/ \+/:/1,2,3,4,5,6'

Output should be
almantas:31949:1:0:00:00:08:?:/usr/bin/pulseaudio -D --log-target=syslog
almantas:31979:12082:0:00:00:06ts/2:bash
almantas:31991:31949:0:00:00:00:?:/usr/lib/pulseaudio/pulse/gconf-helper
almantas:32009:1:0:00:00:06:?:/usr/lib/libgconf2-4/gconfd-2
almantas:32166:31352:0:00:00:00:?:/usr/bin/seahorse-agent --execute x-session-manager
  #2 (permalink)  
Old 02-24-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,298
With awk:

Code:
 awk '{gsub(" ",":",$1)}1' FS=/ OFS=/ file
Regards
  #3 (permalink)  
Old 02-25-2009
eXPlosion eXPlosion is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 3
thanks, but as you see, in the second line there are no leading slash "/" before word "bash" and this script leaves space there :
almantas 31979 12082 0 00:00:06 pts/2 bash
  #4 (permalink)  
Old 02-25-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Code:
 awk '
{ for ( n = 1; n <= 6; ++n ) sub(/ /,":"); print }
'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0