The UNIX and Linux Forums  

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
parsing a string in a shell script asutoshch Shell Programming and Scripting 19 05-26-2008 10:18 PM
Need shell/sed script for grep+string replacement pranavagarwal Shell Programming and Scripting 3 11-15-2007 06:35 AM
string search in folders with particular multiple file extension anikanch UNIX for Dummies Questions & Answers 2 10-28-2005 11:09 AM
shell script: forbid extension Loriel UNIX for Dummies Questions & Answers 3 03-25-2004 04:47 PM
Shell script: Cut / (slash) character in string ThuongTranVN UNIX for Dummies Questions & Answers 4 01-30-2001 12:35 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 11-10-2006
vbm vbm is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 10
shell script string extension

hey,

im looking for a way of extending a string in shell script.
for example i have two strings "." and "abcd",
i need to extend the first string so that it is the same length as the second.
so "." and "abcd" becomes "...." and "abcd",

could someone shed light on how to do this ? thanks
  #2 (permalink)  
Old 11-10-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Code:
[/tmp]$ cat try.ksh
#! /bin/ksh

f="abcd"
o="."

f_len=${#f}
o_len=${#o}

while [[ $o_len -lt $f_len ]]
do
  o="$o."
  o_len=${#o}
done

echo "$o"
echo "$f"
[/tmp]$ ./try.ksh 
....
abcd
[/tmp]$
  #3 (permalink)  
Old 11-10-2006
vbm vbm is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 10
thanks dude, another incredibly simple answer that i overlooked
  #4 (permalink)  
Old 11-10-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
echo "abcd" | sed 's/././g'
  #5 (permalink)  
Old 11-10-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by anbu23
Code:
echo "abcd" | sed 's/././g'
Pretty neat !
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 02:24 PM.


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