LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   insert a symbol with sed (https://www.linuxquestions.org/questions/programming-9/insert-a-symbol-with-sed-224790/)

tonton 08-31-2004 09:26 AM

insert a symbol with sed
 
hello,

I've a variable which return the 5th field in a ligne.

var=`echo $i | cut -d";" -f5`

it returns:
1234
4512
...

I want to insert a ":" in the middle of each number like :
12:34
45:12

i tried whith sed, but i 've an error.

Thnks for your help

ToniT 08-31-2004 09:33 AM

Code:

toni@mario:~$ echo -e '1234\n4567' | sed 's/^\(..\)\(..\)$/\1:\2/'
12:34
45:67
toni@mario:~$


tonton 08-31-2004 10:04 AM

hello,

thanks for your help

i've a messag error ( sed : command garbled 's/^\(..\)\(..\)$/\1:\2/' )

what it means?

thanks

ToniT 08-31-2004 10:09 AM

Did you try that exact command I used?

Are you having what versions of of bash and sed?
Code:

toni@mario:~$ echo $SHELL, $BASH_VERSION
/bin/bash, 3.00.0(1)-release
toni@mario:~$ LC_MESSAGES=C sed --version
GNU sed version 4.1.2
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
toni@mario:~$


tonton 08-31-2004 11:04 AM

hello

it's a sun solaris 5.8

thanks

jlliagre 08-31-2004 11:33 AM

ToniT's script works with Solaris 8:

Code:

$ uname -s -r
SunOS 5.8
 $ echo '1234\n4567' | sed 's/^\(..\)\(..\)$/\1:\2/' 
12:34
45:67
 $



All times are GMT -5. The time now is 01:07 AM.