Apr 25, 2004 #1 ozi403 Technical User Apr 29, 2002 54 TR Hi, I get some outputs like these: fileweek.003 or fileweek:003 or fileweek-003 or fileweek_003 and I try to produce a sequential serie of this output n times like : fileweek.003 fileweek.004 fileweek.005 fileweek.00(n-1) thanks.
Hi, I get some outputs like these: fileweek.003 or fileweek:003 or fileweek-003 or fileweek_003 and I try to produce a sequential serie of this output n times like : fileweek.003 fileweek.004 fileweek.005 fileweek.00(n-1) thanks.
Apr 25, 2004 1 #2 PHV MIS Nov 8, 2002 53,708 FR Something like this ? ls fileweek* | awk -v n=10 '/fileweek/{ if(!match($1,/[0-9][0-9]*/))next file=substr($1,1,RSTART-1) s=substr($1,RSTART,RLENGTH) for(i=s;i<n;++i)print file""sprintf("%0"RLENGTH"d",i) }' Hope This Help, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 Upvote 0 Downvote
Something like this ? ls fileweek* | awk -v n=10 '/fileweek/{ if(!match($1,/[0-9][0-9]*/))next file=substr($1,1,RSTART-1) s=substr($1,RSTART,RLENGTH) for(i=s;i<n;++i)print file""sprintf("%0"RLENGTH"d",i) }' Hope This Help, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
Apr 26, 2004 #3 parbhani Technical User Jul 3, 2002 125 GB HI there , Can you please elaborate your exact question please ?? Regards Upvote 0 Downvote
May 11, 2004 Thread starter #4 ozi403 Technical User Apr 29, 2002 54 TR Sorry, it isn't so clear I think. For example : firstvalue="fileweek:039" n=5 So, I want to make a list like this : fileweek:039 fileweek:040 fileweek:041 fileweek:042 fileweek:043 How can I? Upvote 0 Downvote
Sorry, it isn't so clear I think. For example : firstvalue="fileweek:039" n=5 So, I want to make a list like this : fileweek:039 fileweek:040 fileweek:041 fileweek:042 fileweek:043 How can I?
May 11, 2004 #5 PHV MIS Nov 8, 2002 53,708 FR Try something like this: firstvalue="fileweek:039" n=5 echo "$firstvalue" | awk -v n=$n '/fileweek/{ if(!match($1,/[0-9][0-9]*/))next file=substr($1,1,RSTART-1) s=substr($1,RSTART,RLENGTH) for(i=0;i<n;++i)print file""sprintf("%0"RLENGTH"d",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 Upvote 0 Downvote
Try something like this: firstvalue="fileweek:039" n=5 echo "$firstvalue" | awk -v n=$n '/fileweek/{ if(!match($1,/[0-9][0-9]*/))next file=substr($1,1,RSTART-1) s=substr($1,RSTART,RLENGTH) for(i=0;i<n;++i)print file""sprintf("%0"RLENGTH"d",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
May 12, 2004 1 #6 Ygor Programmer Feb 21, 2003 623 GB Or.. echo $firstvalue| awk -F: '{for(i=0;i<n;i++) printf "%s:%03d\n", $1, $2++}' n=5 Upvote 0 Downvote
May 17, 2004 Thread starter #7 ozi403 Technical User Apr 29, 2002 54 TR Thanks friends. All work successfully. Ygor, when I give a value which have 2 digits to n, it doesn't work n times.What is the problem for your idea? thanks a lot. Upvote 0 Downvote
Thanks friends. All work successfully. Ygor, when I give a value which have 2 digits to n, it doesn't work n times.What is the problem for your idea? thanks a lot.
May 17, 2004 #8 Ygor Programmer Feb 21, 2003 623 GB Perhaps you could post the code and the error. It seems to work for me... $ echo $firstvalue| awk -F: '{for(i=0;i<n;i++) printf "%s:%03d\n", $1, $2++}' n=99 fileweek:039 fileweek:040 fileweek:041 : etc. fileweek:135 fileweek:136 fileweek:137 Upvote 0 Downvote
Perhaps you could post the code and the error. It seems to work for me... $ echo $firstvalue| awk -F: '{for(i=0;i<n;i++) printf "%s:%03d\n", $1, $2++}' n=99 fileweek:039 fileweek:040 fileweek:041 : etc. fileweek:135 fileweek:136 fileweek:137
May 17, 2004 Thread starter #9 ozi403 Technical User Apr 29, 2002 54 TR My script like this, is it right?: #!/bin/ksh #set -x echo "Enter label: \c" read firstvalue echo "How much label: \c" read n for z in . : _ - do if [ "`echo $firstvalue | awk -F"$z" '{ print $1 }'`" != "$firstvalue" ]; then spr=$z if [ `echo $firstvalue | awk -F$spr '{ print $2 }'|wc -c` = 3 ]; then dig=2 fi if [ `echo $firstvalue | awk -F$spr '{ print $2 }'|wc -c` = 4 ]; then dig=3 fi if [ `echo $firstvalue | awk -F$spr '{ print $2 }'|wc -c` = 5 ]; then dig=4 fi if [ `echo $firstvalue | awk -F$spr '{ print $2 }'|wc -c` = 6 ]; then dig=5 fi echo $firstvalue| awk -F$spr '{for(i=0;i<n;i++) printf "%s'$spr'%0'$dig'd\n", $1, $2++}' n=$n fi done Upvote 0 Downvote
My script like this, is it right?: #!/bin/ksh #set -x echo "Enter label: \c" read firstvalue echo "How much label: \c" read n for z in . : _ - do if [ "`echo $firstvalue | awk -F"$z" '{ print $1 }'`" != "$firstvalue" ]; then spr=$z if [ `echo $firstvalue | awk -F$spr '{ print $2 }'|wc -c` = 3 ]; then dig=2 fi if [ `echo $firstvalue | awk -F$spr '{ print $2 }'|wc -c` = 4 ]; then dig=3 fi if [ `echo $firstvalue | awk -F$spr '{ print $2 }'|wc -c` = 5 ]; then dig=4 fi if [ `echo $firstvalue | awk -F$spr '{ print $2 }'|wc -c` = 6 ]; then dig=5 fi echo $firstvalue| awk -F$spr '{for(i=0;i<n;i++) printf "%s'$spr'%0'$dig'd\n", $1, $2++}' n=$n fi done
May 18, 2004 Thread starter #10 ozi403 Technical User Apr 29, 2002 54 TR Hi Ygor, If you try with 10,20 or 34 etc. you can see what the output is. thanks. Upvote 0 Downvote
May 18, 2004 1 #11 vgersh99 Programmer Jul 27, 2000 2,146 US use '-ne' and '-ne' for numeric comparisons in shell. vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+ Upvote 0 Downvote
use '-ne' and '-ne' for numeric comparisons in shell. vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+
May 18, 2004 #12 vgersh99 Programmer Jul 27, 2000 2,146 US '-ne' and '-eq' that is. vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+ Upvote 0 Downvote
'-ne' and '-eq' that is. vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+
May 19, 2004 Thread starter #13 ozi403 Technical User Apr 29, 2002 54 TR PH, Your awk sentence give this error like this : awk: syntax error near line 1 awk: bailing out near line 1 What is wrong for you? Upvote 0 Downvote
PH, Your awk sentence give this error like this : awk: syntax error near line 1 awk: bailing out near line 1 What is wrong for you?
May 19, 2004 #14 vgersh99 Programmer Jul 27, 2000 2,146 US if on Solaris, try using "nawk" instead of 'awk'. vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+ Upvote 0 Downvote
if on Solaris, try using "nawk" instead of 'awk'. vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+
May 22, 2004 Thread starter #15 ozi403 Technical User Apr 29, 2002 54 TR Hi vgersh99, You are right.It is working with nawk, great! Thanks everybody. Upvote 0 Downvote