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!

insert ":" in a field

Status
Not open for further replies.

tonivm

Technical User
Mar 2, 2006
64
ES
Hi everybody:
I'd like to know how could I solve this problem.
I have a file where there is a field as:
0023
And Id like insert ":" as:
00:23
How could I do it?.
Thanks in advance.
 
You may consider the substr function:
substr($1,1,2)":"substr($1,3,2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

Code:
[gray]# any awk[/gray]

[blue]master #[/blue] echo '0023' | awk '{$1=substr($1,1,2)":"substr($1,3)}1'
00:23

[gray]# GNU awk[/gray]

[blue]master #[/blue] echo '0023' | awk '{$1=gensub(/(..)/,"\\1:","",$1)}1'
00:23

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top