| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| The following test script shows what I'm attempting to do. It will end up in a make file translating a make macro for library list into a macro for target dependency. pre_fix=lib suffix=.so echo Starting with: echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe | sed -r \ -e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \ -e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta' # Use lines below if not GNU sed and -r option #-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \ #-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+| \3/\5|g' Current output is: sh junk.txt Starting with: -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe -L/usr/local/lib /usr/local/lib/libtom.so libdick.so libharry.so -L/ usr/lib /usr/lib/libjane.so libdoe.so should look like this when done: /usr/local/lib/libtom.so /usr/local/lib/libdick.so /usr/local/lib/ libharry.so /usr/lib/libjane.so /usr/lib/libdoe.so |
|
#2
| |||
| |||
| In article <070ce6c5-620e-40bb-b1d8-85e07eb9bf69@v16g2000prc.googlegroups.com>, dhighley <dhighley@highley-recommended.com> wrote: >The following test script shows what I'm attempting to do. It will end >up in a make file translating a make macro for library list into a >macro for target dependency. > >pre_fix=lib >suffix=.so >echo Starting with: >echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe >echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe | >sed -r \ >-e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \ >-e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta' > ># Use lines below if not GNU sed and -r option >#-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \ >#-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+| >\3/\5|g' What part of comp.lang.AWK don't you understand? |
|
#3
| |||
| |||
| On Aug 15, 12:17*am, gaze...@shell.xmission.com (Kenny McCormack) wrote: > In article <070ce6c5-620e-40bb-b1d8-85e07eb9b...@v16g2000prc.googlegroups..com>, > > > > dhighley *<dhigh...@highley-recommended.com> wrote: > >The following test script shows what I'm attempting to do. It will end > >up in a make file translating a make macro for library list into a > >macro for target dependency. > > >pre_fix=lib > >suffix=.so > >echo Starting with: > >echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe > >echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe | > >sed -r \ > >-e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \ > >-e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta' > > ># Use lines below if not GNU sed and -r option > >#-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \ > >#-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+| > >\3/\5|g' > > What part of comp.lang.AWK don't you understand? Not meaning to stir the pot I did a search before to see where sed type questions were being asked. There is no sed group and I had posted on comp.editors before. Many books do combine sed and awk. But programming both I do know that they are not that close together as languages. |
|
#4
| |||
| |||
| On 2008-08-15, dhighley <dhighley@highley-recommended.com> wrote: > The following test script shows what I'm attempting to do. It will end > up in a make file translating a make macro for library list into a > macro for target dependency. > > pre_fix=lib > suffix=.so > echo Starting with: > echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe > echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe | > sed -r \ > -e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \ > -e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta' > > # Use lines below if not GNU sed and -r option > #-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \ > #-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+| > \3/\5|g' > > Current output is: > sh junk.txt > Starting with: > -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe > -L/usr/local/lib /usr/local/lib/libtom.so libdick.so libharry.so -L/ > usr/lib /usr/lib/libjane.so libdoe.so > > should look like this when done: > /usr/local/lib/libtom.so /usr/local/lib/libdick.so /usr/local/lib/ > libharry.so /usr/lib/libjane.so /usr/lib/libdoe.so Use awk instead: echo -LAndTheRestOfTheLine | tr ' ' \\n | awk '....(see below)...' And the awk command: awk '$0 ~ /^-L/ {path=$0} $0 ~ /^-l/ {print path "/lib" lib ".so"}' Use an awk function (substr perhaps) in the path=$0 to eliminate the -L You can omit the "tr" command: awk -F' ' Hope it helps you. Best regars, Claudio. |
|
#5
| |||
| |||
| On Aug 16, 12:07*pm, Claudio <clau...@example.org> wrote: > On 2008-08-15, dhighley <dhigh...@highley-recommended.com> wrote: > > > > > The following test script shows what I'm attempting to do. It will end > > up in a make file translating a make macro for library list into a > > macro for target dependency. > > > pre_fix=lib > > suffix=.so > > echo Starting with: > > echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe > > echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe | > > sed -r \ > > -e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \ > > -e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta' > > > # Use lines below if not GNU sed and -r option > > #-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \ > > #-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+| > > \3/\5|g' > > > Current output is: > > sh junk.txt > > Starting with: > > -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe > > -L/usr/local/lib /usr/local/lib/libtom.so libdick.so libharry.so -L/ > > usr/lib /usr/lib/libjane.so libdoe.so > > > should look like this when done: > > /usr/local/lib/libtom.so /usr/local/lib/libdick.so /usr/local/lib/ > > libharry.so /usr/lib/libjane.so /usr/lib/libdoe.so > > Use awk instead: > > echo -LAndTheRestOfTheLine | tr ' ' \\n | awk '....(see below)...' > > And the awk command: > > awk '$0 ~ /^-L/ {path=$0} > $0 ~ /^-l/ {print path "/lib" lib ".so"}' > > Use an awk function (substr perhaps) in the path=$0 to eliminate the -L > > You can omit the "tr" command: awk -F' ' > > Hope it helps you. > > Best regars, > Claudio. Not quite. Below is a working example: #!/bin/sh LIBS='-L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe' echo Starting with: echo $LIBS echo echo what did we get?: echo $LIBS | awk -F' ' ' BEGIN{pre_fix="lib"; suffix=".so";out=""} { for(i=1; i<=NF; i++) { if($i ~ /^-L/) {path=substr($i,3)} if($i ~ /^-l/) {out=out path "/" pre_fix substr($i,3) suffix " "} } } END{print out}' |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.