Operating System - Linux
1827811 Members
1807 Online
109969 Solutions
New Discussion

Insert ":" into some text

 

Insert ":" into some text

How do I insert a : into some text in a file
eg1. turn 0001 into 00:01
eg2. turn 2359 into 23:59

The file will contain several fields that need maniplating like this.

Thanks,
Gary.
Don't chuck bricks at cows.
2 REPLIES 2

Re: Insert ":" into some text

It's ok I've worked it out.
if a=0723 then the following will sort it :-
echo $a | sed 's/^\(..\)\(..\)$/\1:\2/'

Gary.
Don't chuck bricks at cows.
Peter Godron
Honored Contributor

Re: Insert ":" into some text

Gary,
while read record
do
hh=`echo $record | cut -c1,2`
mm=`echo $record | cut -c3,4`
echo $hh:$mm
done < inputfile