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.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
adding spaces for a variable value dnat Shell Programming and Scripting 2 02-26-2008 05:32 AM
Adding spaces to record nvenkat010 Shell Programming and Scripting 3 01-28-2008 01:24 PM
Adding an extra route to the ip routing table Japie89 IP Networking 2 10-18-2007 08:16 PM
adding spaces to a line mgirinath Shell Programming and Scripting 4 03-23-2007 12:38 PM
Adding Trailing Spaces to a file 222001459 UNIX for Dummies Questions & Answers 1 11-04-2004 03:23 PM

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 05-14-2008
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Adding character to spaces in a table

Hi All,

I am trying to get the spaces in the below table to be fill up with a character " - ". For eg, coordinates 0202 is a space but i would want to fill up with " - ". Can anybody help ?

Input:
Code:
                                                        
04  D  H                                     
03  C  G  K                                             
02  B     L                                                   
01  A  E  I                                               
   01 02 03 04
Output:
Code:
04  D  H  -  -                                 
03  C  G  K  -                                           
02  B  -  L  -                                                
01  A  E  I  -                                            
   01 02 03 04
  #2 (permalink)  
Old 05-14-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
A quick solution:
Code:
sed 's/   /  -/g'
This won't work fully if the missing items on the end of each line aren't padded with spaces. In that case a slightly cleverer solution will be required
  #3 (permalink)  
Old 05-15-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
Code:
sed 's/ /-/g' 65258_space.d
  #4 (permalink)  
Old 05-15-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Quote:
Originally Posted by aju_kup View Post
Code:
sed 's/ /-/g' 65258_space.d
Unless I'm missing some significance with the '65258_space.d' (whatever that is), that looks like it would replace every space with a -, producing the following file:
Code:
04--D--H---
03--C--G--K
02--B-----L
01--A--E--I
---01-02-03-04
?
  #5 (permalink)  
Old 05-15-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Hi,

Try this,

sed '/^0/s/ / -/g' filename .


Hi,

Can anybody suggest me how to leave the last line in the substitution.
Requirement is to do substitution in all the lines except the last line.

I tried

sed '!$s/ / -/g' filename ....But its not working ..giving syntax error

Thanks
Penchal
  #6 (permalink)  
Old 05-15-2008
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Quote:
Originally Posted by penchal_boddu View Post
Hi,

Try this,

sed '/^0/s/ / -/g' filename .


Hi,

Can anybody suggest me how to leave the last line in the substitution.
Requirement is to do substitution in all the lines except the last line.

I tried

sed '!$s/ / -/g' filename ....But its not working ..giving syntax error

Thanks
Penchal

The below sed will substitute in all the lines except the last line

Code:
sed '$!s/  / -/g;s/^ -/- /g' inpfile
Regards,
Chella
  #7 (permalink)  
Old 05-15-2008
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Hi Raynon,

Try the below one...

Code:
sed 's/  / -/g;s/^ -/- /g' inpfile
Regards,
Chella
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 12:10 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