Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create directory structure from a no. 1

Status
Not open for further replies.

RVSachin

Technical User
Nov 12, 2001
77
IN
Hi,

If I input a no., for example, 123456, then how do I create a directory-structure as follows after reading the input using Korn-Shell:

d:/123000s/123400s/123456

Thanks,

RV
 
Something like this ?
typeset -Z6 i
read i
a=$(($i/1000*1000))
b=$(($i/100*100))
mkdir -p d:/${a}s/${b}s/$i

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for providing the solution, PHV.

Out of curiosity, I thought of knowing if there's a way of doing this by reading the input no. as a string, read the required part of the string, append appropriate no. of zeroes and create a directory structure using these strings.
I agree that this is a complicated process, just out of curiosity, I wanted to know this.

Thanks again for your time, PHV.

- RV
 
This should work for strings or numbers...
[tt]
read i
mkdir -p d:/${i%???}000s/${i%??}00s/$i[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top