shell script string extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script string extension
# 1  
Old 11-10-2006
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  
Old 11-10-2006
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  
Old 11-10-2006
thanks dude, another incredibly simple answer that i overlooked Smilie
# 4  
Old 11-10-2006
Code:
echo "abcd" | sed 's/././g'

# 5  
Old 11-10-2006
Quote:
Originally Posted by anbu23
Code:
echo "abcd" | sed 's/././g'

Pretty neat !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to get duplicate string

Hi All, I have a requirement where I have to get the duplicate string count and uniq error message. Below is my file: Rejected - Error on table TableA, column ColA. Error String 1. Rejected - Error on table TableA, column ColB. Error String 2. Rejected - Error on table TableA, column... (6 Replies)
Discussion started by: Deekhari
6 Replies

2. Shell Programming and Scripting

Finding file extension on C Shell script

I very new to C Shell. I am trying to do is read from Command line. Find the if the file is zip, .txt, symbloic link,pipe, unknow (if file is not zip, txt, sy....) here is what I what got so far. I am very stuck atm Please help me out : If the file is symblooc link what file is link to ... (12 Replies)
Discussion started by: madbull41
12 Replies

3. Shell Programming and Scripting

shell script to change the extension of a file

I have a directory that contains several files, out of which some files are have an extra extension for example file1.new.new.new file2.new.new.new file3.new.new.new file4.new.new.new i want to write a shell script that rename all such file with only single extension like file1.new... (7 Replies)
Discussion started by: mukulverma2408
7 Replies

4. Shell Programming and Scripting

How to get the last value from a string in shell script?

I have to get the last value from a string, below is the example string String -> Here is the test string 12233 O/P -> 12233 String -> Hello world 500 O/P -> 500 String -> 300 O/P -> 300 Please help (2 Replies)
Discussion started by: vel4ever
2 Replies

5. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

6. Shell Programming and Scripting

Extract string in shell script

Hi All, i've a string /u/asak/DATE/TEST_LOGS/20110704_033429_test11_w_2_120/HDD/test11_w_2_12/hd-120 i need to extract string which is test11_w_2_120, this can be start with anything, numbers, characters with underscore etc.. but the time stamp 20110704_033429_ with two underscores will be... (5 Replies)
Discussion started by: asak
5 Replies

7. Shell Programming and Scripting

Help on shell script (string operations)

Hey everyone. So the background of the problem is that the ps3 does not support the mkv container, but DOES support the avi one. Here is the script to convert one file with the name hardcoded in: #!/bin/sh mencoder -oac... (2 Replies)
Discussion started by: wua05
2 Replies

8. UNIX for Dummies Questions & Answers

Shell script to rename or change file extension case.

I searched the forum, but there was different type of rename. Hello. I have files in folder. Like: xxxxxxxx1.html or xxxxxxxx2.txt or xxxxxxxx3.tar.gz and how to rename or change file extension case to xxxxxxxx1.htm or xxxxxxx2.TXT or (5 Replies)
Discussion started by: Sheldon
5 Replies

9. UNIX for Dummies Questions & Answers

string search in folders with particular multiple file extension

Hi, I am newbie in UNIX so please excuse for my questions. Is there a a way to search for string in files within folder and sub folder in particluar file extensions. Ex. search for ABC in folder 'A'(including it's sub folders) in html, xml files. Thanks, Ani (2 Replies)
Discussion started by: anikanch
2 Replies

10. UNIX for Dummies Questions & Answers

shell script: forbid extension

Rather new to unix, so please don't beat me! I'm trying to get a list of files into a variable that I can use throughout the rest of the script. The challenge is that I need to exclude a certain extension from the list, and I'm having trouble with it. For example: item_a item_a.exe... (3 Replies)
Discussion started by: Loriel
3 Replies
Login or Register to Ask a Question