Gentoo Archives: gentoo-dev

From: Ryan Hill <dirtyepic@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: RFC: sed script redundancy
Date: Fri, 28 Oct 2011 00:59:46
Message-Id: 20111027190836.28f911fe@gentoo.org
In Reply to: [gentoo-dev] RFC: sed script redundancy by Jeroen Roovers
1 On Fri, 20 May 2011 17:39:22 +0200
2 Jeroen Roovers <jer@g.o> wrote:
3
4 > for a while now I've been wondering if all those sed scripts in all
5 > those ebuilds are really effective.
6 >
7 > To find out, I've tried a couple of angles on a sed hook that basically
8 > dissects the sed command line provided, divides everything up into sed
9 > scripts, files being processed and other options, and runs everything
10 > through diff to get some meaningful QA output as to the effective use
11 > of the sed scripts invoked.
12 >
13 > Of course some of the time a sed script falsely seems to be ineffective,
14 > but could be, when it uses some variable or output that varies depending
15 > on the platform you run it on, like with the likes of $(get_libdir).
16 >
17 > I've looked into sed's internal solutions to no avail, but something
18 > like -i[SUFFIX] might help, since it gives you a backup file to compare
19 > with the file that's being streamed.
20 >
21 > The idea is to pass the result to
22 > | diff -u $file $file[SUFFIX]
23 > to figure out what was changed, and what sed script changed it.
24 >
25 > Any help?
26
27 Sorry, old thread. :) You can use the 'w' flag to write a log file of lines
28 changed. This includes lines changed where the replacement ended up the same
29 as the text matched (eg. lib->$(get_libdir)). Which means you can do
30 something like:
31
32 dirtyepic@tundra ~ $ cat test
33 foo
34 foobar
35 bar
36 foobarfoo
37 dirtyepic@tundra ~ $ sed -i -e 's:foo:foo:gw /dev/stdout' test | wc -l
38 3
39
40 I think only gnu sed can do the stdout thing.
41
42 --
43 fonts, gcc-porting, it makes no sense how it makes no sense
44 toolchain, wxwidgets but i'll take it free anytime
45 @ gentoo.org EFFD 380E 047A 4B51 D2BD C64F 8AA8 8346 F9A4 0662

Attachments

File name MIME type
signature.asc application/pgp-signature