* Alan W. Irwin wrote on Friday, September 16, 2005 19:22 CEST:
He reported for a specific case the following bad result from
the command line:
nm -f posix -A zlib.dll.a | \
sed -n -e '1,100{/ I /{x;/import/!{s/^/import/;h;p;};x;};}'
The expected "import" output did not appear.
However, if he tries instead
nm -f posix -A zlib.dll.a | \
sed -n -e '1,100{/ I /{x;/import/!{s/^.*/import/;h;p;};x;};}'
import
Note the expected "import" output does appear with this
change to the sed
logic. To complete this here is the result of nm -f posix -A
zlib.dll.a
without the sed filtering:
zlib.dll.a[dt.o]: .bss b 00000000
zlib.dll.a[dt.o]: .data d 00000000
zlib.dll.a[dt.o]: .idata$4 i 00000000
zlib.dll.a[dt.o]: .idata$5 i 00000000
zlib.dll.a[dt.o]: .idata$7 i 00000000
zlib.dll.a[dt.o]: .text t 00000000
zlib.dll.a[dt.o]: __zlib_dll_a_iname I 00000000
zlib.dll.a[dh.o]: .bss b 00000000
zlib.dll.a[dh.o]: .data d 00000000
zlib.dll.a[dh.o]: .idata$2 i 00000000
zlib.dll.a[dh.o]: .idata$4 i 00000000
zlib.dll.a[dh.o]: .idata$5 i 00000000
zlib.dll.a[dh.o]: .text t 00000000
zlib.dll.a[dh.o]: __head_zlib_dll_a I 00000000
zlib.dll.a[dh.o]: __zlib_dll_a_iname U
zlib.dll.a[dh.o]: fthunk i 00000004
zlib.dll.a[dh.o]: hname i 00000004
...
The strings with " I " in them trigger the rest of the sed
script which
is why at least the second form produces the "import" response.
I bet this is an end-of-line issue. There is probably a \r
that destroys something.
Anyway, this sed script should simler, faster, more robust
and equivalent.
sed -n -e '1,100{/ I /{s/.*/import/;p;q;};}'
However, I can't reproduce here so someone better test first...