sed - simple question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed - simple question
# 8  
Old 03-29-2007
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/'

# 9  
Old 03-29-2007
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

# 10  
Old 03-29-2007
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
# 11  
Old 03-29-2007
Quote:
Originally Posted by anbu23
Code:
$ echo dfd.dfd | sed 's/\([0-9]*\)\.\([0-9]*\)/\1,\2/'
dfd,dfd

Yeah, catch! Smilie

Code:
perl -e ' while (<>) { chomp; if( $_ =~ /(\d+)\.(\d+)/ ) { s/\./,/g; print "$_\n"; } else { print "$_\n" } }' filename

# 12  
Old 03-29-2007
Quote:
Originally Posted by anbu23
Code:
sed -e "s/\([0-9]\)\./\1,/g" -e "s/\.\([0-9]\)/,\1/g" file

Smilie

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

# 13  
Old 03-29-2007
Quote:
Originally Posted by matrixmadhan
Smilie

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.

# 14  
Old 03-29-2007
this is cool! Smilie

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Simple SED Question

I don't understand this command behavior. echo "abc" |sed 's/a/&_&/' (4 Replies)
Discussion started by: Vartika18
4 Replies

2. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

3. Shell Programming and Scripting

Simple sed script question

Script newbie, so I'm sure I'm missing something obvious here, but how come this simple script does not work? #!/bin/bash ... (3 Replies)
Discussion started by: KidCactus
3 Replies

4. Shell Programming and Scripting

simple sed question - replace from phrase to end of line

I have the following line an in input file I want to digest with sed and simple replace the bold part with a variable defined in my bash script. I can do this in several sed operations but I know there must be a way to do it in a single sed line. What is the syntax? Line in file:... (1 Reply)
Discussion started by: graysky
1 Replies

5. Shell Programming and Scripting

Simple sed question.

I have a log output with a format similar to this: a=1, b= 2 c=0, d= 45, e=100 ... and so on. I figure I can just use awk or something to pipe the file to sed, but I'm trying to replace all the values above with 0. I've tried: cat blah | sed 's/=\(.*\),/0/'but that didn't work. ... (6 Replies)
Discussion started by: throw_a_stick
6 Replies

6. Shell Programming and Scripting

simple sed question

How do I remove parentheses using sed? input (192.168.1.1) output 192.168.1.1 (4 Replies)
Discussion started by: streetfighter2
4 Replies

7. Shell Programming and Scripting

simple awk/sed/tr question

I have a file CREATE TABLE DDD_EXT --- 1000 ( val u1 val u1 ); CREATE TABLE dsdasd_EXT --- 1323 ( val u1 val u1 ); CREATE TABLE AAAAAA_EXT --- 1222 ( val u1 val u1 ); CREATE TABLE E_EXT --- 11 ( val u1 val u1 (2 Replies)
Discussion started by: jville
2 Replies

8. Shell Programming and Scripting

simple sed question

hi is it possible to cut this two semicolon separated sed commands echo "string2 string3 string1" | sed s'/string1//g;s/string2//g' output: " string3 " to just one sed command without semicolon? thanks in advance funksen (10 Replies)
Discussion started by: funksen
10 Replies

9. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies

10. UNIX for Dummies Questions & Answers

Simple sed question

Is there an easier way to do the following: echo "|||||||" | sed 's/||/|0|/g; s/||/|0|/g' which would give the following |0|0|0|0|0|0| If it is not run twice it will not pick up the second occurance of the || and leave it empty as in echo "|||||||" | sed 's/||/|0|/g' which would give... (3 Replies)
Discussion started by: maverick
3 Replies
Login or Register to Ask a Question