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!

Need help w/if

Status
Not open for further replies.

sabetik

IS-IT--Management
Nov 16, 2003
80
GU
Please check this program I am not getting result.
Here sample data:
H124124424 25124 2541
D1254254 2541245 2524 25425 2568
D1254235 2658254 2556 25422 7898
H124124424 25124 2541

BEGIN {
if(substr($0,1,1)=="H") {
# do this
#remove first Character
sub( /./, "" )
fh1 = substr($0,2,7)
fh2 = substr($0,9,7)
fh3 = substr($0,16,8)
fh4 = substr($0,24,8)
fh5 = substr($0,32,40)
printf ("%-7s %-7s %-8s %-8s %-40s\n",fh1,fh2,fh3,fh4,fh5 ) > "test.DAT"

} else if(substr($0,1,1)=="D") {
# do this
sub( /./, "" )

fd1 = substr($0,2,8)
fd2 = substr($0,10,8)
fd3 = substr($0,18,4)
fd4 = substr($0,22,15)
# Insert "-" after each group of 5 chars.
gsub( /...../, "&-", fd4 )
# Remove any trailing "-".
sub( /-$/, "", fd4 )
fd5 = substr($0,37,6)
fd6 = substr($0,43,10)

}



}
 
Remove the BEGIN keyword.
Print the fdX fields.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV, thanks for the help. It did work. I have couples questions:
1. how can inser a comma"," after each field.
2. Why this option does not remove the trailing "-"
Ex:
21063-5061 -
but if my part number is 12 the I am ok T2088-90302-10

Thanks Again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top