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

CSvFormat

Status
Not open for further replies.

sabetik

IS-IT--Management
Nov 16, 2003
80
GU
Need help with the following file:

Part-no. Desc price
-----------------------------------------
16861014060 car mat 0 000002521
16861016080 car mat 0 000002084
1244265982145 car mat 0 000012532

I like to ou put be this way:
"68610-14060","car mat","25.21"
"686610-14060","car mat","20.84"
"24426-59821-45',"car mat","125.32"

If part-no. is 10 digit then it will be this format xxxxx-xxxxx if part-no. 12 digit the it will be this format xxxxx-xxxxx-xx.

Thanks in Advance for help

 
Provided the input doesn't contain tab char, you may try something like this:
awk '/^1/{
pn=substr($1,2,5)"-"substr($1,7,5)(length($1)==13?"-"substr($1,12):"")
d=substr($0,17,10);sub(/ *$/,"",d)
pr=$(NF)/100
printf "\"%s\",\"%s\",\"%.2f\"\n",pn,d,pr
}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
awk '
{
printf("\"%s-%s", substr($1,1,5), substr($1,6,5));
if((len = length($1)) >10) printf("-%s",substr($1,12,len-10));
printf("\",\"%s %s\",\"%.2f\"\n",$2,$3,$5/100);
}' in >out

### sabetik: can you please try to help yourself, there are
### tons of similar exemples in this forum ...
### PHV: sorry, i did not see your post



:) guggach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top