Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Substring in Korn Shell Script
Name: Sam Date: September 10, 2003 at 18:13:21 Pacific OS: Solaris CPU/Ram: F50 / 10 G
Name: Nails Date: September 10, 2003 at 20:39:01 Pacific
Reply:
Hi:
Since you're data is fixed length, you can do something like this:
while read x do f1=$(echo $x|cut -c1-4) f2=$(echo $x|cut -c5-6) f3=$(echo $x|cut -c7-8) f4=$(echo $x|cut -c9-10) f5=$(echo $x|cut -c11-12) f6=$(echo $x|cut -c13-14) f7=$(echo $x|cut -c15-20) # printf all on one line printf "%s-%s-%s-%s.%s.%s.%s\n" $f1 $f2 $f3 $f4 $f5 $f6 $f7 done data.file # you need a 'less than sign' between done and the data file
Somebody can probably come up with a cool korn shell pattern to do this.
Regards,
Nails
0
Response Number 2
Name: WilliamRobertson Date: September 11, 2003 at 06:23:42 Pacific
Reply:
Or you could do it with sed:
sed 's/\(....\)\(..\)\(..\)\(..\)\(..\)\(..\)\(......\)/\1-\2-\3-\4.\5.\6.\7/' data.file
Summary: hi , I have a problem in Korn shell script(in dtksh) my program is like that...... #!/usr/dt/bin/dtksh awk ' BEGIN { FS = ":"; # print '$1','$2','$3' cmdargs = '$#' } { if( cmdargs == 3) {...
Summary: hi, i want to create a directory from my cgi script written in korn shell. but there is no out put. means that this script work for other commands like ls and cd but don't work fo mkdir commands. here...