The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple Question aforball UNIX for Dummies Questions & Answers 3 03-04-2008 01:26 PM
simple sed question funksen Shell Programming and Scripting 10 04-08-2007 02:54 PM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 11:29 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 10:03 AM
Simple ksh question frustrated1 Shell Programming and Scripting 1 11-05-2003 09:41 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8  
Old 03-28-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
Quote:
Originally Posted by jacoden
Code:
sed 's/[0-9]\.[0-9]/,/g' filename
this wont work, as single digit is considered


Code:
echo "1234.23" | sed 's/\([0-9]*\)\.\([0-9]*\)/\1,\2/'
Reply With Quote
Forum Sponsor
  #9  
Old 03-28-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by matrixmadhan
Code:
echo "1234.23" | sed 's/\([0-9]*\)\.\([0-9]*\)/\1,\2/'
Code:
$ echo dfd.dfd | sed 's/\([0-9]*\)\.\([0-9]*\)/\1,\2/'
dfd,dfd
Reply With Quote
  #10  
Old 03-28-2007
dj -------
 

Join Date: Feb 2007
Location: Cochin/Bangalore, India
Posts: 418
Quote:
Originally Posted by matrixmadhan
this wont work, as single digit is considered


Code:
echo "1234.23" | sed 's/\([0-9]*\)\.\([0-9]*\)/\1,\2/'
Yes.it was a mistake...

sed 's/\([0-9]\)\.\([0-9]\)/\1,\2/g' filename

should be fine
Reply With Quote
  #11  
Old 03-28-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
Quote:
Originally Posted by anbu23
Code:
$ echo dfd.dfd | sed 's/\([0-9]*\)\.\([0-9]*\)/\1,\2/'
dfd,dfd
Yeah, catch!

Code:
perl -e ' while (<>) { chomp; if( $_ =~ /(\d+)\.(\d+)/ ) { s/\./,/g; print "$_\n"; } else { print "$_\n" } }' filename
Reply With Quote
  #12  
Old 03-28-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
Quote:
Originally Posted by anbu23
Code:
sed -e "s/\([0-9]\)\./\1,/g" -e "s/\.\([0-9]\)/,\1/g" file


What is the need to replace number and ' . ' as number and ' , '
or
' . ' and number as ' , ' and number in a combined expression

just one of the them would do,

Code:
sed "s/\([0-9]\)\./\1,/g" a
or
Code:
sed "s/\.\([0-9]\)/,\1/g"  a
Reply With Quote
  #13  
Old 03-28-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by matrixmadhan


What is the need to replace number and ' . ' as number and ' , '
or
' . ' and number as ' , ' and number in a combined expression

just one of the them would do,

Code:
sed "s/\([0-9]\)\./\1,/g" a
or
Code:
sed "s/\.\([0-9]\)/,\1/g"  a
It wont work in the following cases
Code:
$ echo ".34" | sed "s/\([0-9]\)\./\1,/g"
.34
$ echo "23." | sed "s/\.\([0-9]\)/,\1/g"
23.
Reply With Quote
  #14  
Old 03-28-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
this is cool!

It didnt strike for me about the ".34" and "34." kind of numbers

Code:
perl -e ' while (<>) { chomp; if( $_ =~ /(\d+)\.(\d+)/ || $_ =~ /\.(\d+)/ || $_ =~ /(\d+)\./ ) { s/\./,/g; print "$_\n"; } else { print "$_\n" } }' filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0