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

Substring in Korn Shell Script

Status
Not open for further replies.

samitk

IS-IT--Management
Sep 10, 2003
1
US
I have data in current format

20030910091500000000
20030910114500000000
20030910020000000000

I need to convert this to

2003-09-10-09.15.00.000000
2003-09-10-11.45.00.000000
2003-09-10-02.00.00.000000

Any suggestions - how I can do this??

Appreciate ur help..
 
Awk has a substring function...

awk '{print substr($0,1,4) &quot;-&quot; substr($0,5,2) &quot;- etc&quot;}' <file1

 
Try something like this:
Code:
awk '{y=substr($0,1,4);m=substr($0,5,2);d=substr($0,7,2)
H=substr($0,9,2);M=substr($0,11,2);S=substr($0,13,2)
printf &quot;%s-%s-%s-%s.%s.%s.%s\n&quot;,y,m,d,H,M,S,substr($0,15)
}' /path/to/inputfile >/path/to/outputfile

Hope This Help
PH.
 
Another solution:

[tt]sed 's/\(....\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1-\2-\3-\4.\5.\6./' inputfile > outputfile[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top