Create directories with regular expression


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Create directories with regular expression
# 8  
Old 09-01-2008
Try using bc and ksh:

for i in `echo "for(i=1;i<11;i++) i"|bc` ; do printf "mkdir test%02d\n" $i; done
# 9  
Old 09-01-2008
Computer Bc

Try using ksh and bc calculator:

for i in `echo "for(i=1;i<11;i++) i"|bc` ; do printf "mkdir test%02d\n" $i; done
# 10  
Old 09-01-2008
The last one would apparently have worked if the directory hadn't already existed.

The seq command doesn't exist on your system; it's not completely standard, so no real surprise there. Anyway, it does roughly what the for loop in the awk script does, so don't worry about it.

The awk script is wrong; sorry for not testing it properly. Try this instead.

Code:
mkdir `awk 'END { for (i=1; i<=10; ++i) printf "test%02i\n", i }' /dev/null`

... this time after making sure the directories you want do not already exist (maybe create an empty directory under /tmp/ and run this there). This is by and large equivalent to the script radoulov posted. (My posting was not intended to override his; we simply answered at the same time, and he finished composing his reply first.)
# 11  
Old 09-01-2008
Another way to use seq (obviously no benefit to the OP, but for the sake of discussion...):

Code:
seq -f 'mkdir test%02g' 1 10 | bash

# 12  
Old 09-01-2008
Or actually, I prefer:

Code:
mkdir $(seq -f 'test%02g' 1 10)

# 13  
Old 09-03-2008
Thank you era..., this command has worked.

mkdir `awk 'END { for (i=1; i<=10; ++i) printf "test%02i\n", i }' /dev/null`
# 14  
Old 09-03-2008
Annihilannic,
Thanks for the reply, but seq is not there on my system and I use korn shell.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep with Regular expression now working on file directories

Hello Everyone, I have a file sam1 with the below content SYSYSID;MANDT;/SIE/AD_Z0M_INDX;/SIE/AD_Z0M_KEY1 echo $Regex \bSYSYSID\b|\bMANDT\b|\b/SIE/AD_Z0M_INDX\b|\b/SIE/AD_Z0M_KEY1\b cat sam1 | grep -Eo $Regex I expect the result as SYSYSID MANDT /SIE/AD_Z0M_INDX /SIE/AD_Z0M_KEY1... (4 Replies)
Discussion started by: sam99
4 Replies

2. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

3. Programming

How to use regular expression in C/C++ ?

how to code with regexp.h some one can give me instance? thx (4 Replies)
Discussion started by: AKB48
4 Replies

4. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

5. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

6. Shell Programming and Scripting

Regular Expression

Hi, In Perl What should be the regular expression for 1-23. I tried with |1|2. But it is not working. I have a code snippet like below $state = 0; while( $state != 1 ) { $hour=<STDIN>; if ( $hour =~ /|1|2/) { print "Integer within range.\n"; $state = 1;... (3 Replies)
Discussion started by: siba.s.nayak
3 Replies

7. UNIX for Dummies Questions & Answers

using regular expression for directories in find command

Hi, I want to find the files available in a directory /var/user/*/*/data/. I tried using the command "find /var/user/ -path '*/*/data/ -name '*' -type f" it says find: 0652-017 -path is not a valid option and then i tried using "find /var/user/ -name '*/*/data/*' -type f" but its not... (3 Replies)
Discussion started by: vinothbabu12
3 Replies

8. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

9. Linux

Regular expression to extract "y" from "abc/x.y.z" .... i need regular expression

Regular expression to extract "y" from "abc/x.y.z" (2 Replies)
Discussion started by: rag84dec
2 Replies

10. Shell Programming and Scripting

Regular Expression + Aritmetical Expression

Is it possible to combine a regular expression with a aritmetical expression? For example, taking a 8-numbers caracter sequece and casting each output of a grep, comparing to a constant. THX! (2 Replies)
Discussion started by: Z0mby
2 Replies
Login or Register to Ask a Question