Sujet : Re: How can I use sed to insert a character into a file?
De : nunojsilva (at) *nospam* invalid.invalid (Nuno Silva)
Groupes : comp.os.linux.miscDate : 08. Jul 2024, 21:43:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6hfg4$103fh$1@dont-email.me>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
On 2024-07-08, Jon Danniken wrote:
I'm sure this is trivial to most here, but sed confounds me. I have
an xml file with content following this format:
>
<type:color>000000</type:color>
<type:color>FFFFFF</type:color>
>
The information within the tags are hex colors (many different
colors), but they need to begin with a pound sign (#) to work in a
particular application, ie:
>
<type:color>#000000</type:color>
<type:color>#FFFFFF</type:color>
>
How can I use sed to append the pound symbol in this file? Using sed
4.8 BTW, thanks!
in general, my guess would be something like (for sed's s command)
s@\(<type:color>\)\(......\)\(</type:color>\)@\1#\2\
3@gOther approaches will surely be possible, say, if these are the only
sequences of hex digits that show up, or if this always appears on a
line by itself (so maybe matching lines on <type:color> and then
replacing the sequence of digits with #& could be done too - & being the
matched text)
Treat this like it had been written on a napkin over my knee, I may have
made a stupid mistake above or overlooked something obvious, surely
others will chime in with better suggestions. There's also
comp.unix.programmers, and I think also a shell group, which might be
helpful audiences too.
-- Nuno Silva