<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(51,51,255)">Using sed to simply edit items in place usually works like this:<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(51,51,255)">
sed -i 's,OLDSTRING,NEWSTRING,g;s,OLDSTRING2,NEWSTRIN2G,g' FILENAME<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(51,51,255)">The semicolon separates search/replace strings and the g makes it replace all occurrences.<br>
</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(51,51,255)">If the text to be replaced has comas (,) you can use / as a delimiter such as |,#,etc.<br></div></div><div class="gmail_extra">
<br clear="all"><div><div dir="ltr"><div>-- JD Austin<br>Voice: 480.269.4335 (480 2MY Geek)<br><a href="mailto:jd@twingeckos.com" target="_blank">jd@twingeckos.com</a></div><br></div></div>
<br><br><div class="gmail_quote">On Tue, Jul 2, 2013 at 11:18 AM, Dazed_75 <span dir="ltr"><<a href="mailto:lthielster@gmail.com" target="_blank">lthielster@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Thanks guys. I must not be doing what you suggest correctly or maybe I did not describe the problem well (to edit the chosen lines in place in the source file). In any case, after experimenting on a copy of the file without success I went ahead and did the edits manually to get the job done. I hope neither of you spent too much time on it but I do appreciate the effort.<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Tue, Jul 2, 2013 at 7:08 AM, der.hans <span dir="ltr"><<a href="mailto:PLUGd@lufthans.com" target="_blank">PLUGd@lufthans.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">Am 02. Jul, 2013 schwätzte Dazed_75 so:<br>
<br>
moin moin,<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have some C code with lines that look like:<br>
stuff1; stuff2; spPtr+=stuff3; maybesomestuff4<br>
<br>
I can find only the lines of interest using grep spPtr+=foo.c but I<br>
wondered if I could easily use sed to convert those lines to<br>
stuff1; spPtr+=stuff3; stuff2; maybesomestuff4<br>
<br>
so basically with ; as a delimiter, swapping group 2 and 3 but only for<br>
those lines containing "spPtr+="<br>
<br>
Any ideas?<br>
</blockquote>
<br></div>
$ echo "1; 2; 3; 4;" | sed -re 's/^([^;]+;)([^;]+;)([^;]+;)/\<u></u>1\3\2/'<br>
1; 3; 2; 4;<br>
$<br>
<br>
Combining the 3 capture groups into one is left as an exercise for the<br>
reader :).<br>
<br>
Obviously, if any of the fields contain a ;, then that match won't do what<br>
you're wanting on that line.<br>
<br>
ciao,<br>
<br>
der.hans<span><font color="#888888"><br>
-- <br>
# <a href="http://www.LuftHans.com/" target="_blank">http://www.LuftHans.com/</a> <a href="http://www.LuftHans.com/Classes/" target="_blank">http://www.LuftHans.com/<u></u>Classes/</a><br>
# Wer bereit ist, grundlegende Freiheiten aufzugeben, um sich<br>
# kurzfristige Sicherheit zu verschaffen, der hat weder Freiheit<br>
# noch Sicherheit verdient. -- Benjamin Franklin (1706 - 1790)</font></span><br></div></div>---------------------------------------------------<br>
PLUG-discuss mailing list - <a href="mailto:PLUG-discuss@lists.phxlinux.org" target="_blank">PLUG-discuss@lists.phxlinux.org</a><br>
To subscribe, unsubscribe, or to change your mail settings:<br>
<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/mailman/listinfo/plug-discuss</a><br></blockquote></div><div class="im"><br><br clear="all"><br>-- <br>Dazed_75 a.k.a. Larry<br>
<br>Please protect my address like I protect yours. When sending messages to multiple recipients, use the BCC:
(Blind carbon copy). Remove addresses from a forwarded message body before clicking Send. <br>
</div></div>
<br>---------------------------------------------------<br>
PLUG-discuss mailing list - <a href="mailto:PLUG-discuss@lists.phxlinux.org">PLUG-discuss@lists.phxlinux.org</a><br>
To subscribe, unsubscribe, or to change your mail settings:<br>
<a href="http://lists.phxlinux.org/mailman/listinfo/plug-discuss" target="_blank">http://lists.phxlinux.org/mailman/listinfo/plug-discuss</a><br></blockquote></div><br></div>