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!

sequence with awk 3

Status
Not open for further replies.

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.
 
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
 
HI there ,

Can you please elaborate your exact question please ??

Regards
 
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?

 
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
 
Or..

echo $firstvalue| awk -F: '{for(i=0;i<n;i++) printf "%s:%03d\n", $1, $2++}' n=5
 
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.
 
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
 
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
 
Hi Ygor,

If you try with 10,20 or 34 etc. you can see what the output is.

thanks.
 
use '-ne' and '-ne' for numeric comparisons in shell.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
'-ne' and '-eq' that is.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
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?
 
if on Solaris, try using "nawk" instead of 'awk'.


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi vgersh99,

You are right.It is working with nawk, great!

Thanks everybody.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top