Need some sed help

JD Austin jd at twingeckos.com
Tue Jul 2 11:33:17 MST 2013


Using sed to simply edit items in place usually works like this:
sed -i 's,OLDSTRING,NEWSTRING,g;s,OLDSTRING2,NEWSTRIN2G,g' FILENAME
The semicolon separates search/replace strings and the g makes it replace
all occurrences.
If the text to be replaced has comas (,) you can use / as a delimiter such
as |,#,etc.

-- JD Austin
Voice: 480.269.4335 (480 2MY Geek)
jd at twingeckos.com



On Tue, Jul 2, 2013 at 11:18 AM, Dazed_75 <lthielster at gmail.com> wrote:

> 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.
>
>
> On Tue, Jul 2, 2013 at 7:08 AM, der.hans <PLUGd at lufthans.com> wrote:
>
>> Am 02. Jul, 2013 schwätzte Dazed_75 so:
>>
>> moin moin,
>>
>>
>>  I have some C code with lines that look like:
>>> stuff1; stuff2; spPtr+=stuff3; maybesomestuff4
>>>
>>> I can find only the lines of interest using grep spPtr+=foo.c but I
>>> wondered if I could easily use sed to convert those lines to
>>> stuff1; spPtr+=stuff3; stuff2; maybesomestuff4
>>>
>>> so basically with ; as a delimiter, swapping group 2 and 3 but only for
>>> those lines containing "spPtr+="
>>>
>>> Any ideas?
>>>
>>
>> $ echo "1; 2; 3; 4;" | sed -re 's/^([^;]+;)([^;]+;)([^;]+;)/\**1\3\2/'
>> 1; 3; 2; 4;
>> $
>>
>> Combining the 3 capture groups into one is left as an exercise for the
>> reader :).
>>
>> Obviously, if any of the fields contain a ;, then that match won't do what
>> you're wanting on that line.
>>
>> ciao,
>>
>> der.hans
>> --
>> #  http://www.LuftHans.com/        http://www.LuftHans.com/**Classes/<http://www.LuftHans.com/Classes/>
>> #  Wer bereit ist, grundlegende Freiheiten aufzugeben, um sich
>> #  kurzfristige Sicherheit zu verschaffen, der hat weder Freiheit
>> #  noch Sicherheit verdient.  --  Benjamin Franklin  (1706 - 1790)
>> ---------------------------------------------------
>> PLUG-discuss mailing list - PLUG-discuss at lists.phxlinux.org
>> To subscribe, unsubscribe, or to change your mail settings:
>> http://lists.phxlinux.org/mailman/listinfo/plug-discuss
>>
>
>
>
> --
> Dazed_75 a.k.a. Larry
>
> 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.
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.phxlinux.org
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.phxlinux.org/mailman/listinfo/plug-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phxlinux.org/pipermail/plug-discuss/attachments/20130702/951fe1e6/attachment.html>


More information about the PLUG-discuss mailing list