Re: sed question



Works like a champ and I was sooo close. Thanks a lot for your help!!

On Fri, Aug 19, 2011 at 2:28 PM, Josh Miller <joshua@xxxxxxxxxxxxxxxxx>wrote:

On 08/19/2011 11:06 AM, Rob DeSanno wrote:
...

What I am trying to do is to change the "-" character to something else
ONLY
when it is next to a number [0-9]. What makes this a challenge for me is
that it can also exist next to a letter but never more than once next to a
number.

The line I am using is below and works fine for what I need expect that
the
first digit of the number at the end is cut off in the table I am trying
to
build.

'102.1'>Columbus-612
'104.1'>Fredericksburg-628
'108.1'>Garden-Grove-736
'101.1'>Mission-Viejo-1514
'104.1'>Fort-Worth-418
'1030.1'>Ft.-Lauderdale-304
'1050.1'>Hamilton-713

sed -e "s/^'/\<tr\>\<td\>/" $stores_down | sed -e "s/'>/\<\/td\>\<td\>/" |
*sed
-e "s/-[0-9]/\<\/td\>\<td\>/"* | sed -e "s/$/\<\/td\>\<\/tr\>/">> $log

...

Hi Rob,

You're matching the hyphen and the digit following it, without capturing
the digit to include in the resulting output.

Try this, I've split the sed command into a sed script (file.sed) and the
input file into another file (file.txt):

cat file.txt

'102.1'>Columbus-612
'104.1'>Fredericksburg-628
'108.1'>Garden-Grove-736
'101.1'>Mission-Viejo-1514
'104.1'>Fort-Worth-418
'1030.1'>Ft.-Lauderdale-304
'1050.1'>Hamilton-713

cat file.sed
# for each line beginning with a single quote, end the table and row
s/^'/\<tr\>\<td\>/
# for each '>, replace with cell divider
s/'>/\<\/td\>\<td\>/
# for each hyphen digit, replace hyphen with cell divider
s/-\([0-9]\)/\<\/td\>\<td\>\1/
# for each line ending, replace with cell/row ending
s/$/\<\/td\>\<\/tr\>/


sed -f file.sed file.txt
<tr><td>102.1</td><td>**Columbus</td><td>612</td></tr>
<tr><td>104.1</td><td>**Fredericksburg</td><td>628</**td></tr>
<tr><td>108.1</td><td>Garden-**Grove</td><td>736</td></tr>
<tr><td>101.1</td><td>Mission-**Viejo</td><td>1514</td></tr>
<tr><td>104.1</td><td>Fort-**Worth</td><td>418</td></tr>
<tr><td>1030.1</td><td>Ft.-**Lauderdale</td><td>304</td></**tr>
<tr><td>1050.1</td><td>**Hamilton</td><td>713</td></tr>



HTH,
--
Josh Miller
Open Source Solutions Architect
http://itsecureadmin.com/

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@**redhat.com<redhat-list-request@xxxxxxxxxx>
?subject=unsubscribe
https://www.redhat.com/**mailman/listinfo/redhat-list<https://www.redhat.com/mailman/listinfo/redhat-list>

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list



Relevant Pages

  • Re: sed question
    ... You're matching the hyphen and the digit following it, without capturing the digit to include in the resulting output. ... > cat file.txt ... replace hyphen with cell divider ... replace with cell/row ending ...
    (RedHat)
  • Re: why no output
    ... the Grave Hand of Darren Cubitt Did Inscribe: ... What are the contents of the input file? ... Your program wont work if you only input a short digit sequence ... Terror is a war against whomever Bush wants to be at war with. ...
    (comp.lang.c)
  • Re: why no output
    ... What are the contents of the input file? ... If the first character is ... Your program wont work if you only input a short digit sequence since you are returning false as soon as an EOF is seen. ... Darren (aka: qarnos) ...
    (comp.lang.c)
  • Re: egrep match nine digit
    ... abc there is a nine digit number i need only a egrep pattern which ... Your input file contains an eight digit number, ...
    (comp.unix.shell)