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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add "-"between numbers

Status
Not open for further replies.

kamsabeti

IS-IT--Management
Feb 26, 2008
21
I have 10 and 12 digist number that I like to add "-" between them orginal number are:

1234567890 need to display as 12345-67890
123456789012 need to display as 12345-67890-12

I did on ASP but I need do it on AWK.
Here what I did on ASP:

fh4=trim(mid(str,21,15)) 'Part_No
pn=mid(fh4,1,5)&"-"&mid(fh4,6,5)&"-"&mid(fh4,11,5)
if right(pn,1)="-" then
pn=left(pn,11)
Thanks
Kamran
 
Here my simple code:

{

#read header
pt = substr($0,2,15)
# change the format to xxxx-xxxxx-xx

nrc = substr($0,20,1)
npt = substr($0,24,15)
# change the format to xxxx-xxxxx-xx

cost = substr($0,41,9)
desc= substr($0,57,20)
mvc = substr($0,177,2)

printf ("%-15s,%-1s,%-15s,%7.2f,%-20s,%2s \n",pt,nrc,npt,cost/100,desc,mvc) > "guam.txt"
}
 
I was able to fixt it from getting information from other posts. Thanks
 
Code:
awk '
{
    x=substr($0,11)
    if (x)
	print substr($0,1,5)"-"substr($0,6,5)"-"substr($0,11)
    else
	print substr($0,1,5)"-"substr($0,6,5)
}' /path/to/urfile
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top