Question regarding sed usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question regarding sed usage
# 1  
Old 01-04-2012
Question Question regarding sed usage

I have a html file with the following content:-

<font face=verdana color=#000000>108946</font>
<font face=verdana color=#000000>234346</font>

I want to format the values inside the font tag using thousand separator. I have the following command which can be used for adding thousand separator:-

cat test.html | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'

But it will convert the tag property numbers (color=#000000) also to thousand separator like below:-

<font face=verdana color=#000,000>108,946</font>
<font face=verdana color=#000,000>234,346</font>

How can I modify the sed options for avoiding this?


# 2  
Old 01-04-2012
See if this works for you:
Code:
sed -e :a -e 's/>\(.*[0-9]\)\([0-9]\{3\}\)/>\1,\2/;ta' Inp_File

Note that there is no need to use "cat".
This User Gave Thanks to Shell_Life For This Post:
# 3  
Old 01-04-2012
Code:
echo '<font face=verdana color=#000000>108946</font>' | sed 's:#\([0-9]\{3\}\)\([0-9]\{3\}\):#\1,\2:1'

# 4  
Old 01-04-2012
Thank you -Question regarding sed usage

The following command works:-

sed -e :a -e 's/>\(.*[0-9]\)\([0-9]\{3\}\)/>\1,\2/;ta' Inp_File

By the way the following command is changing the tag property, not the tag value:-

echo '<font face=verdana color=#000000>108946</font>' | sed 's:#\([0-9]\{3\}\)\([0-9]\{3\}\):#\1,\2:1'

But this one is also informative syntax. Thank you. Appreciate your help. Smilie

# 5  
Old 01-04-2012
Oh... I misread what you wanted to change:
Code:
echo '<font face=verdana color=#00000>108946</font>' | sed 's:>\([0-9]\{3\}\)\([0-9]\{3\}\):>\1,\2:1'

This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed command usage question

How to work x in sed command? I know x command is swaps the contents of pattern space and hold space. But i am unable to understand it's working? (4 Replies)
Discussion started by: Vartika18
4 Replies

2. UNIX for Dummies Questions & Answers

Ln usage question

Is it possible to assign a symbolic link to a network folder, without that folder being mounted? Thanks! (1 Reply)
Discussion started by: nerdcurious
1 Replies

3. Programming

Question about erand48 usage

Hi, Following is the trimmed down version of the code I'm using to generate a set of random numbers using erand48 #include <stdio.h> #include <stdlib.h> #include <math.h> main() { unsigned short xsubi; xsubi=10; double r; int x; int i=0,... (14 Replies)
Discussion started by: santosh_sugur
14 Replies

4. UNIX for Dummies Questions & Answers

rsync usage question

Hello folks; I'm using rsync on my Ubuntu servers to sync a remote folders on a remote machine to a local folders on a local machine. one thing i couldn't get to work is how to exclude folder. I know i'm suppose to use "exclude" argument but every time i do, i still see the excluded directory... (0 Replies)
Discussion started by: Katkota
0 Replies

5. Shell Programming and Scripting

sed usage

Hi, I want to replace some character whenever there is a space using sed. Input file name: aaa command i am trying is sed 's/^$/A/g' aaa (2 Replies)
Discussion started by: rakeshbharadwaj
2 Replies

6. Shell Programming and Scripting

Sed usage

How can i use sed to change "Linux Cpu (EDF).sh" to "LinuxCpuEDF.sh"? I want to replace the spaces and brackets. (4 Replies)
Discussion started by: proactiveaditya
4 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. Shell Programming and Scripting

usage of sed question for experts

I need a little help with sed. Basically, I need to parse out selections from the output of hddtemp so conky can display some hdd temps for me. I have hddtemp in daemon mode so A simple 'nc localhost 7634' displays the following: $ nc localhost 7634... (3 Replies)
Discussion started by: audiophile
3 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Linux

sed usage

Hi , I have a question. How do I replace 2 words in one line like this IN CLO07 INDEX IN CLOIX07 to IN CLO07_S02 INDEX IN CLOIX07_S02 But one thing to remember is that there are lots of words like CLODM001 . So the only matching pattern is "IN CLO" sample file... (4 Replies)
Discussion started by: capri_drm
4 Replies
Login or Register to Ask a Question