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!

Adding Comma

Status
Not open for further replies.

sabetik

IS-IT--Management
Nov 16, 2003
80
GU
I am tring to separte the filed by comma. Is there a way to add a commas to the following lines:
If line start with H then add commas to the lines
H9806201A2472352005040120050401000000000000000000000 H,9806201,A247235,20050401,200504010,00000000000000000000 If line start with D then insert commas

DAC237823V3103X 00224522033240 00000100000063160000000000063160 14

D,AC237823,V3103,X00224522033240, 000001,000000631,60000000000063,160 14


and this is my input file:
H9806201A2472352005040120050401000000000000000000000
DAC237823V3103X 00224522033240 00000100000063160000000000063160 14
DAC237823V3103X 00234522033240 00000100000063160000000000063160 14
H9806201O4713392005040120050401000014500001280000081
D8CJL1147V3003X 00234420047060 00000100001045950000000001045950 14
H9806201O4713612005040120050401000088100008810000762
D8CJG1118TS0503 00022330019295 00000100000014970000000000014970 14
D8CJG1118TS0503 0031161006934583 00000200000054620000000000109240 14
D8CJG1118TS0503 00453121035110 00000100000034690000000000034690 14
 
In the awk man page take a look at the substr function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for the info. I know substr. But I am not sure how to use if statement.
ex
if first char "H" do this else if first char "D" then do this

Thanks
Kamran
 
if(substr($0,1,1)=="H" {
# do this
} else if(substr($0,1,1)=="D" {
# do that
}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
OOps, sorry for the typos:
if(substr($0,1,1)=="H") {
# do this
} else if(substr($0,1,1)=="D") {
# do that
}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top