Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You have had a long-term stimulation relative to business.


comp / comp.os.linux.misc / Re: How can I use sed to insert a character into a file?

SubjectAuthor
* How can I use sed to insert a character into a file?Jon Danniken
+- Re: How can I use sed to insert a character into a file?Nuno Silva
`* Re: How can I use sed to insert a character into a file?Thomas Zajic
 `- Re: How can I use sed to insert a character into a file?Jon Danniken

1
Subject: How can I use sed to insert a character into a file?
From: Jon Danniken
Newsgroups: comp.os.linux.misc
Organization: A noiseless patient Spider
Date: Mon, 8 Jul 2024 18:44 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nonesuch@nottodaynortomorroreither.org (Jon Danniken)
Newsgroups: comp.os.linux.misc
Subject: How can I use sed to insert a character into a file?
Date: Mon, 8 Jul 2024 13:44:54 -0500
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <v6hc36$vv1m$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 08 Jul 2024 20:44:55 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8dff31a87a669269c6a237cff9733ad6";
logging-data="1047606"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y21jRSwJ92WPCShG9ibi9nOYXuYfeT9k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:jwryD8cmlVVpk2W2je0BBGxcQhI=
Content-Language: en-US
View all headers

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!

Subject: Re: How can I use sed to insert a character into a file?
From: Nuno Silva
Newsgroups: comp.os.linux.misc
Organization: A noiseless patient Spider
Date: Mon, 8 Jul 2024 19:43 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nunojsilva@invalid.invalid (Nuno Silva)
Newsgroups: comp.os.linux.misc
Subject: Re: How can I use sed to insert a character into a file?
Date: Mon, 08 Jul 2024 20:43:00 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <v6hfg4$103fh$1@dont-email.me>
References: <v6hc36$vv1m$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Mon, 08 Jul 2024 21:43:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2bb0366cb8d58357519f9a4388f8a5be";
logging-data="1052145"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rAM8CFurN9qH5DibIeh00"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
Cancel-Lock: sha1:C5kzoP6l9YSapFSZsSJdJxrPgtw=
View all headers

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@g

Other 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

Subject: Re: How can I use sed to insert a character into a file?
From: Thomas Zajic
Newsgroups: comp.os.linux.misc
Date: Mon, 8 Jul 2024 19:56 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: zlatko@gmx.at (Thomas Zajic)
Newsgroups: comp.os.linux.misc
Subject: Re: How can I use sed to insert a character into a file?
Date: Mon, 8 Jul 2024 21:56:01 +0200
Lines: 30
Message-ID: <slrnv8oh2h.fr2.zlatko@disclosure.zlatk0.net>
References: <v6hc36$vv1m$1@dont-email.me>
X-Trace: individual.net 6igzVBHXLd+EY+Py0M+IYgeWZa5E9lWoXuQtnhITih1iX5EnU=
X-Orig-Path: news.zlatk0.net!not-for-mail
Cancel-Lock: sha1:384zyiuk9qCsAdn5qLpfyZjUKeM= sha256:7EbpYQv4CZ008d43EW5BOuQ2i0Mw+qIZCs7ZeYu9CTk=
X-Signature-Color: blue
X-Eric-Conspiracy: There is no conspiracy
X-Registered-Linux-User: 63207
X-Organization: FAQ-Team for at.linux
X-Face: $Bj#y0]DSsWPX(UJnJ@"s}e}4FU`ep9qSk<Gbp@G"+\UxynXojl4S)|.Ff/Y72G5Cc&s?
$HK/bs)HT-L.Ccf>`+*:=e/BlD{EJ;\k:{+y(sfWA}Vm:U:Arl;!r(B@rw^}ON`|mW?&o&y6EpRq[
;D6Tv;zGnMz~u
User-Agent: slrn/1.0.3 (Linux)
View all headers

* Jon Danniken <nonesuch@nottodaynortomorroreither.org>

> 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

sed -i -e 's,<type:color>,<type:color>#,' file.xml

Could be done more sophistic & elegant, but I think it's more readable
this way. :-)

HTH & HAND
Thomas
--
=-------------------------------------------------------------------------=
- Thomas "ZlatkO" Zajic <zlatko@gmx.at> Linux-6.6 & slrn-1.0.3a -
- "In layman's terms: speedy thing goes in, speedy thing comes out." -
=-------------------------------------------------------------------------=

Subject: Re: How can I use sed to insert a character into a file?
From: Jon Danniken
Newsgroups: comp.os.linux.misc
Organization: A noiseless patient Spider
Date: Mon, 8 Jul 2024 21:47 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nonesuch@nottodaynortomorroreither.org (Jon Danniken)
Newsgroups: comp.os.linux.misc
Subject: Re: How can I use sed to insert a character into a file?
Date: Mon, 8 Jul 2024 16:47:17 -0500
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <v6hmp5$11kpf$1@dont-email.me>
References: <v6hc36$vv1m$1@dont-email.me>
<slrnv8oh2h.fr2.zlatko@disclosure.zlatk0.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 08 Jul 2024 23:47:18 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8dff31a87a669269c6a237cff9733ad6";
logging-data="1102639"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18q7QbPCUPTrulPIX0ePdusK80E4+xK958="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vZcFKeQ/S9Z1FgGnb/ZK9W8VSoE=
Content-Language: en-US
In-Reply-To: <slrnv8oh2h.fr2.zlatko@disclosure.zlatk0.net>
View all headers

On 7/8/24 14:56, Thomas Zajic wrote:
> * Jon Danniken <nonesuch@nottodaynortomorroreither.org>
>
>> 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
>
> sed -i -e 's,<type:color>,<type:color>#,' file.xml
>
> Could be done more sophistic & elegant, but I think it's more readable
> this way. :-)
>
>
> HTH & HAND
> Thomas
Thank you Thomas, that worked great! Very much appreciated.

Jon

1

rocksolid light 0.9.8
clearnet tor