LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-31-2004, 09:26 AM   #1
tonton
LQ Newbie
 
Registered: Aug 2004
Posts: 4

Rep: Reputation: 0
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
 
Old 08-31-2004, 09:33 AM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Code:
toni@mario:~$ echo -e '1234\n4567' | sed 's/^\(..\)\(..\)$/\1:\2/'
12:34
45:67
toni@mario:~$
 
Old 08-31-2004, 10:04 AM   #3
tonton
LQ Newbie
 
Registered: Aug 2004
Posts: 4

Original Poster
Rep: Reputation: 0
hello,

thanks for your help

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

what it means?

thanks
 
Old 08-31-2004, 10:09 AM   #4
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
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:~$
 
Old 08-31-2004, 11:04 AM   #5
tonton
LQ Newbie
 
Registered: Aug 2004
Posts: 4

Original Poster
Rep: Reputation: 0
hello

it's a sun solaris 5.8

thanks
 
Old 08-31-2004, 11:33 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
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
 $
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert CRLF's with sed? unSpawn Programming 6 11-22-2006 07:46 AM
Mandrake can't insert ath_pci.ko - unknown symbol Elomis Linux - Software 0 05-07-2005 08:27 AM
insert string with sed greg108 Programming 7 02-18-2005 01:11 PM
sed command to insert tab? iluvatar Linux - Software 4 06-29-2004 01:56 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 06:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration