<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body style="background-color: #fff;">
<span style="display:none"> </span>
<!--~-|**|PrettyHtmlStartT|**|-~-->
<div id="ygrp-mlmsg" style="position:relative;">
<div id="ygrp-msg" style="z-index: 1;">
<!--~-|**|PrettyHtmlEndT|**|-~-->
<div id="ygrp-text" >
<p>
<div class="moz-cite-prefix">Em 28/03/2018 16:22,
<a class="moz-txt-link-abbreviated" href="mailto:***@mknet.com.br">***@mknet.com.br</a> [shell-script] escreveu:<br>
</div>
<blockquote type="cite" cite="mid:p9gq1h+***@YahooGroups.com"> <span> </span>
<div id="ygrp-text">
<p>Olá pessoal, tudo bem?<br>
<br>
Preciso de uma ajuda. Tenho uma string e preciso fazer
algumas substituições.<br>
<br>
A string está estruturada assim:<br>
<br>
ADDITEM=(número entre 1 e 99999),(número entre 1 e
99999),(qualquer caractere alfanumérico ou não,
visível,incluindo ponto,vírgula, exclamação, interrogação,
etc)&(repetição do padrão iniciando com ADDITEM)<br>
<br>
Esta é a string original:<br>
<br>
ADDITEM=24720,1,BITS PHIL.CTPOHR N2 X 70MM
C/10&ADDITEM=24722,1,BITS PHIL.CTPOHR N2 X 127MM
C/10&ADDITEM=24723,1,BITS PHIL.CTPOHR N2 X 150MM
C/10&ADDITEM=24724,1,BITS PHIL.CTPOHR TITAN.2X25MM
C/10&ADDITEM=24725,1,BITS PHIL.CTPOHR TITAN.2X50MM
C/10&ADDITEM=14862,10,BITS PHIL.MAKITA N,1 X 25MM /
656&ADDITEM=14863,20,BITS PHIL.MAKITA N,2 X 25MM /
657&ADDITEM=20026,20,BITS PHIL.MAKITA N,3 X 25MM / 65
&ADDITEM=14865,10,BITS PHIL.MAKITA N.1 X 50MM /
666&ADDITEM=14866,10,BITS PHIL.MAKITA N.2 X 50MM / 667<br>
<br>
Preciso substituir a primeira e a segunda vírgula após
ADDITEM, ambas por </td><td><br>
<br>
Não posso simplesmente pedir ao sed para substituir todas
as vírgulas pois há produtos que tem vírgula na descrição.<br>
<br>
Ao final a string ficará assim:<br>
<br>
<tr><td>24720</td><td>1</td><td>BITS
PHIL.CTPOHR N2 X 70MM
C/10</td><td>24722</td><td>1</td><td>BITS
PHIL.CTPOHR N2 X 127MM
C/10</td><td>24723</td><td>1</td><td>BITS
PHIL.CTPOHR N2 X 150MM
C/10</td><td>24724</td><td>1</td><td>BITS
PHIL.CTPOHR TITAN.2X25MM
C/10</td><td>24725</td><td>1</td><td>BITS
PHIL.CTPOHR TITAN.2X50MM
C/10</td><td>14862</td><td>10</td><td>BITS
PHIL.MAKITA N,1 X 25MM /
656</td><td>14863</td><td>20</td><td>BITS
PHIL.MAKITA N,2 X 25MM /
657</td><td>20026</td><td>20</td><td>BITS
PHIL.MAKITA N,3 X 25MM / 65
</td><td>14865</td><td>10</td><td>BITS
PHIL.MAKITA N.1 X 50MM /
666</td><td>14866</td><td>10</td><td>BITS
PHIL.MAKITA N.2 X 50MM / 667</tr><br>
</p>
<p><span><br>
</span></p>
<p><span>Quanto às substituições no início e no final da
string nenhum problema. O uso do sed com ^ e $ resolvem
a questão. <br>
</span></p>
<p><span><br>
</span></p>
<p><span>O ponto é identificar a primeira e a segunda
vírgula após ADDITEM e fazer a substituição.</span></p>
<p><span><br>
</span></p>
<p><span>Alguém consegue me ajudar?<br class="yui-cursor">
</span></p>
</div>
<!-- end group email -->
</blockquote>
<p>Veja aí se isso resolve <br>
</p>
<p> sed -r
's/(ADDITEM=[0-9]{1,5})([,])([0-9])([,])*./\1<\/td><td>\3<\/td><td>/g'<br>
<br>
</p>
</p>
</div>
<!--~-|**|PrettyHtmlStart|**|-~-->
<div style="color: #fff; height: 0;">__._,_.___</div>
<div style="clear:both"> </div>
<div id="fromDMARC" style="margin-top: 10px;">
<hr style="height:2px ; border-width:0; color:#E3E3E3; background-color:#E3E3E3;">
Enviado por: Luiz Alberto <***@yahoo.com.br> <hr style="height:2px ; border-width:0; color:#E3E3E3; background-color:#E3E3E3;">
</div>
<div style="clear:both"> </div>
<table cellspacing=4px style="margin-top: 10px; margin-bottom: 10px; color: #2D50FD;">
<tbody>
<tr>
<td style="font-size: 12px; font-family: arial; font-weight: bold; padding: 7px 5px 5px;" >
<a style="text-decoration: none; color: #2D50FD" href="https://br.groups.yahoo.com/neo/groups/shell-script/conversations/messages/40825;_ylc=X3oDMTJxZm5pcTdpBF9TAzk3NDkwNDM3BGdycElkAzE5NDEzMTIEZ3Jwc3BJZAMyMTM3MTExMjU0BG1zZ0lkAzQwODI1BHNlYwNmdHIEc2xrA3JwbHkEc3RpbWUDMTUyMjMzMTIyOQ--?act=reply&messageNum=40825">Responder através da web</a>
</td>
<td>•</td>
<td style="font-size: 12px; font-family: arial; padding: 7px 5px 5px;" >
<a href="mailto:***@yahoo.com.br?subject=Res%3A%20Re%3A%20%5Bshell-script%5D%20sed%20replace%20na%20primeira%20e%20segunda%20ocorr%3Dc3%3Daancia_ap%3Dc3%3Db3s_string" style="text-decoration: none; color: #2D50FD;">
</a>
</td>
<td>•</td>
<td style="font-size: 12px; font-family: arial; padding: 7px 5px 5px;">
<a href="mailto:shell-***@yahoogrupos.com.br?subject=Res%3A%20Re%3A%20%5Bshell-script%5D%20sed%20replace%20na%20primeira%20e%20segunda%20ocorr%3Dc3%3Daancia_ap%3Dc3%3Db3s_string" style="text-decoration: none; color: #2D50FD">
através de email </a>
</td>
<td>•</td>
<td style="font-size: 12px; font-family: arial; padding: 7px 5px 5px;" >
<a href="https://br.groups.yahoo.com/neo/groups/shell-script/conversations/newtopic;_ylc=X3oDMTJlY2swMHRkBF9TAzk3NDkwNDM3BGdycElkAzE5NDEzMTIEZ3Jwc3BJZAMyMTM3MTExMjU0BHNlYwNmdHIEc2xrA250cGMEc3RpbWUDMTUyMjMzMTIyOQ--" style="text-decoration: none; color: #2D50FD">Adicionar um novo tópico</a>
</td>
<td>•</td>
<td style="font-size: 12px; font-family: arial; padding: 7px 5px 5px;color: #2D50FD;" >
<a href="https://br.groups.yahoo.com/neo/groups/shell-script/conversations/topics/40821;_ylc=X3oDMTM2a210dWJsBF9TAzk3NDkwNDM3BGdycElkAzE5NDEzMTIEZ3Jwc3BJZAMyMTM3MTExMjU0BG1zZ0lkAzQwODI1BHNlYwNmdHIEc2xrA3Z0cGMEc3RpbWUDMTUyMjMzMTIyOQR0cGNJZAM0MDgyMQ--" style="text-decoration: none; color: #2D50FD;">Mensagens neste tópico</a>
(4)
</td>
</tr>
</tbody>
</table>
<!------- Start Nav Bar ------>
<!-- |**|begin egp html banner|**| -->
<!-- |**|end egp html banner|**| -->
<div id="ygrp-grfd" style="font-family: Verdana; font-size: 12px; padding: 15px 0;">
<!-- |**|begin egp html banner|**| -->
---------------------------------------------------------------------<BR>
Esta lista não admite a abordagem de outras liguagens de programação, como perl, C etc. Quem insistir em não seguir esta regra será moderado sem prévio aviso.<BR>
---------------------------------------------------------------------<BR>
Sair da lista: shell-script-***@yahoogrupos.com.br<BR>
---------------------------------------------------------------------<BR>
Esta lista é moderada de acordo com o previsto em <a href="http://www.listas-discussao.cjb.net">http://www.listas-discussao.cjb.net</a><BR>
---------------------------------------------------------------------<BR>
Servidor Newsgroup da lista: news.gmane.org<BR>
Grupo: gmane.org.user-groups.programming.shell.brazil<BR>
<BR>
<!-- |**|end egp html banner|**| -->
</div>
<!-- |**|begin egp html banner|**| -->
<div id="ygrp-vital" style="background-color: #f2f2f2; font-family: Verdana; font-size: 10px; margin-bottom: 10px; padding: 10px;">
<span id="vithd" style="font-weight: bold; color: #333; text-transform: uppercase; "><a href="https://br.groups.yahoo.com/neo/groups/shell-script/info;_ylc=X3oDMTJlZWt1MXVmBF9TAzk3NDkwNDM3BGdycElkAzE5NDEzMTIEZ3Jwc3BJZAMyMTM3MTExMjU0BHNlYwN2dGwEc2xrA3ZnaHAEc3RpbWUDMTUyMjMzMTIyOQ--" style="text-decoration: none;">Visite seu Grupo</a></span>
<ul style="list-style-type: none; margin: 0; padding: 0; display: inline;">
<li style="border-right: 1px solid #000; font-weight: 700; display: inline; padding: 0 5px; margin-left: 0;">
<span class="cat"><a href="https://br.groups.yahoo.com/neo/groups/shell-script/members/all;_ylc=X3oDMTJmZGVrODFpBF9TAzk3NDkwNDM3BGdycElkAzE5NDEzMTIEZ3Jwc3BJZAMyMTM3MTExMjU0BHNlYwN2dGwEc2xrA3ZtYnJzBHN0aW1lAzE1MjIzMzEyMjk-" style="text-decoration: none;">Novos usuários</a></span>
<span class="ct" style="color: #ff7900;">2</span>
</li>
</ul>
</div>
<div id="ft" style="font-family: Arial; font-size: 11px; margin-top: 5px; padding: 0 2px 0 0; clear: both;">
<a href="https://br.groups.yahoo.com/neo;_ylc=X3oDMTJkOHZoMjBpBF9TAzk3NDkwNDM1BGdycElkAzE5NDEzMTIEZ3Jwc3BJZAMyMTM3MTExMjU0BHNlYwNmdHIEc2xrA2dmcARzdGltZQMxNTIyMzMxMjI5" style="float: left;"><img src="
Loading Image..." height="19" width="141" alt="Yahoo! Grupos" style="border: 0;"/></a>
<div style="color: #747575; float: right;"> • <a href="https://info.yahoo.com/privacy/br/yahoo/groups/details.html" style="text-decoration: none;">Privacidade</a> • <a href="mailto:shell-script-***@yahoogrupos.com.br?subject=Sair do grupo" style="text-decoration: none;">Sair do grupo</a> • <a href="https://info.yahoo.com/legal/br/yahoo/utos/terms/" style="text-decoration: none;">Termos de uso</a> </div>
</div>
<br>
<!-- |**|end egp html banner|**| -->
</div> <!-- ygrp-msg -->
<!-- Sponsor -->
<!-- |**|begin egp html banner|**| -->
<div id="ygrp-sponsor" style="width:160px; float:right; clear:none; margin:0 0 25px 0; background: #fff;">
<!-- Start Recommendations -->
<div id="ygrp-reco">
</div>
<!-- End Recommendations -->
</div> <!-- |**|end egp html banner|**| -->
<div style="clear:both; color: #FFF; font-size:1px;">.</div>
</div>
<img src="http://geo.yahoo.com/serv?s=97490437/grpId=1941312/grpspId=2137111254/msgId=40825/stime=1522331229" width="1" height="1"> <br>
<img src="http://y.analytics.yahoo.com/fpc.pl?ywarid=515FB27823A7407E&a=10001310322279&js=no&resp=img" width="1" height="1">
<div style="color: #fff; height: 0;">__,_._,___</div>
<!--~-|**|PrettyHtmlEnd|**|-~-->
</body>
<!--~-|**|PrettyHtmlStart|**|-~-->
<head>
<style type="text/css">
<!--
#ygrp-mkp {
border: 1px solid #d8d8d8;
font-family: Arial;
margin: 10px 0;
padding: 0 10px;
}
#ygrp-mkp hr {
border: 1px solid #d8d8d8;
}
#ygrp-mkp #hd {
color: #628c2a;
font-size: 85%;
font-weight: 700;
line-height: 122%;
margin: 10px 0;
}
#ygrp-mkp #ads {
margin-bottom: 10px;
}
#ygrp-mkp .ad {
padding: 0 0;
}
#ygrp-mkp .ad p {
margin: 0;
}
#ygrp-mkp .ad a {
color: #0000ff;
text-decoration: none;
}
#ygrp-sponsor #ygrp-lc {
font-family: Arial;
}
#ygrp-sponsor #ygrp-lc #hd {
margin: 10px 0px;
font-weight: 700;
font-size: 78%;
line-height: 122%;
}
#ygrp-sponsor #ygrp-lc .ad {
margin-bottom: 10px;
padding: 0 0;
}
#actions {
font-family: Verdana;
font-size: 11px;
padding: 10px 0;
}
#activity {
background-color: #e0ecee;
float: left;
font-family: Verdana;
font-size: 10px;
padding: 10px;
}
#activity span {
font-weight: 700;
}
#activity span:first-child {
text-transform: uppercase;
}
#activity span a {
color: #5085b6;
text-decoration: none;
}
#activity span span {
color: #ff7900;
}
#activity span .underline {
text-decoration: underline;
}
.attach {
clear: both;
display: table;
font-family: Arial;
font-size: 12px;
padding: 10px 0;
width: 400px;
}
.attach div a {
text-decoration: none;
}
.attach img {
border: none;
padding-right: 5px;
}
.attach label {
display: block;
margin-bottom: 5px;
}
.attach label a {
text-decoration: none;
}
blockquote {
margin: 0 0 0 4px;
}
.bold {
font-family: Arial;
font-size: 13px;
font-weight: 700;
}
.bold a {
text-decoration: none;
}
dd.last p a {
font-family: Verdana;
font-weight: 700;
}
dd.last p span {
margin-right: 10px;
font-family: Verdana;
font-weight: 700;
}
dd.last p span.yshortcuts {
margin-right: 0;
}
div.attach-table div div a {
text-decoration: none;
}
div.attach-table {
width: 400px;
}
div.file-title a, div.file-title a:active, div.file-title a:hover, div.file-title a:visited {
text-decoration: none;
}
div.photo-title a, div.photo-title a:active, div.photo-title a:hover, div.photo-title a:visited {
text-decoration: none;
}
div#ygrp-mlmsg #ygrp-msg p a span.yshortcuts {
font-family: Verdana;
font-size: 10px;
font-weight: normal;
}
.green {
color: #628c2a;
}
.MsoNormal {
margin: 0 0 0 0;
}
o {
font-size: 0;
}
#photos div {
float: left;
width: 72px;
}
#photos div div {
border: 1px solid #666666;
height: 62px;
overflow: hidden;
width: 62px;
}
#photos div label {
color: #666666;
font-size: 10px;
overflow: hidden;
text-align: center;
white-space: nowrap;
width: 64px;
}
#reco-category {
font-size: 77%;
}
#reco-desc {
font-size: 77%;
}
.replbq {
margin: 4px;
}
#ygrp-actbar div a:first-child {
/* border-right: 0px solid #000;*/
margin-right: 2px;
padding-right: 5px;
}
#ygrp-mlmsg {
font-size: 13px;
font-family: Arial, helvetica,clean, sans-serif;
*font-size: small;
*font: x-small;
}
#ygrp-mlmsg table {
font-size: inherit;
font: 100%;
}
#ygrp-mlmsg select, input, textarea {
font: 99% Arial, Helvetica, clean, sans-serif;
}
#ygrp-mlmsg pre, code {
font:115% monospace;
*font-size:100%;
}
#ygrp-mlmsg * {
line-height: 1.22em;
}
#ygrp-mlmsg #logo {
padding-bottom: 10px;
}
#ygrp-msg p a {
font-family: Verdana;
}
#ygrp-msg p#attach-count span {
color: #1E66AE;
font-weight: 700;
}
#ygrp-reco #reco-head {
color: #ff7900;
font-weight: 700;
}
#ygrp-reco {
margin-bottom: 20px;
padding: 0px;
}
#ygrp-sponsor #ov li a {
font-size: 130%;
text-decoration: none;
}
#ygrp-sponsor #ov li {
font-size: 77%;
list-style-type: square;
padding: 6px 0;
}
#ygrp-sponsor #ov ul {
margin: 0;
padding: 0 0 0 8px;
}
#ygrp-text {
font-family: Georgia;
}
#ygrp-text p {
margin: 0 0 1em 0;
}
#ygrp-text tt {
font-size: 120%;
}
#ygrp-vital ul li:last-child {
border-right: none !important;
}
-->
</style>
</head>
<!--~-|**|PrettyHtmlEnd|**|-~-->
</html>
<!-- end group email -->