Bash/Sed issue

Hi

Im having problems with bash and sed ... anyone care to take a look.

Code:
[lbl@dm ~/zyxel-dslam-miner/trunk]$ cat oids.conf | grep ADSL
ADSL .1.3.6.1.2.1.2.2.1.7.POS ifAdminStatus
ADSL .1.3.6.1.2.1.2.2.1.8.POS ifOperStatus
ADSL .1.3.6.1.2.1.10.94.1.1.1.1.4.POS adslLineConfProfile
ADSL .1.3.6.1.2.1.10.94.1.1.3.1.8.POS adslAturCurrAttainableRate
ADSL .1.3.6.1.2.1.10.94.1.1.2.1.8.POS adslAtucCurrAttainableRate
ADSL .1.3.6.1.2.1.10.94.1.1.5.1.2.POS adslAturChanCurrTxRate
ADSL .1.3.6.1.2.1.10.94.1.1.4.1.2.POS adslAtucChanCurrTxRate
ADSL .1.3.6.1.2.1.10.94.1.1.3.1.4.POS adslAturCurrSnrMgn
ADSL .1.3.6.1.2.1.10.94.1.1.2.1.4.POS adslAtucCurrSnrMgn
ADSL .1.3.6.1.2.1.10.94.1.1.3.1.5.POS adslAturCurrAtn
ADSL .1.3.6.1.2.1.10.94.1.1.2.1.5.POS adslAtucCurrAtn
ADSL .1.3.6.1.2.1.10.94.1.1.3.1.7.POS adslAturCurrOutputPwr
ADSL .1.3.6.1.2.1.10.94.1.1.2.1.7.POS adslAtucCurrOutputPwr
ADSL .1.3.6.1.2.1.10.94.1.1.5.1.1.POS adslAturChanInterleaveDelay
ADSL .1.3.6.1.2.1.10.94.1.1.4.1.1.POS adslAtucChanInterleaveDelay
ADSL .1.3.6.1.2.1.10.94.1.1.11.1.3.POS adslAturChanCorrectedBlks
ADSL .1.3.6.1.2.1.10.94.1.1.10.1.3.POS adslAtucChanCorrectedBlks
ADSL .1.3.6.1.2.1.10.94.1.1.7.1.4.POS adslAturPerfESs
ADSL .1.3.6.1.2.1.10.94.1.1.6.1.5.POS adslAtucPerfESs
ADSL .1.3.6.1.2.1.10.94.1.1.6.1.6.POS adslAtucPerfInits
ADSL .1.3.6.1.2.1.10.94.3.1.20.1.1.POS adslAturPerfStatSesL
ADSL .1.3.6.1.2.1.10.94.3.1.18.1.3.POS adslAtucPerfStatSesL
ADSL .1.3.6.1.2.1.10.94.3.1.18.1.4.POS adslAtucPerfStatUasL
ADSL .1.3.6.1.2.1.10.94.3.1.20.1.2.POS adslAturPerfStatUasL
ADSL .1.3.6.1.2.1.10.94.1.1.3.1.6.POS adslAturCurrStatus
ADSL .1.3.6.1.2.1.10.94.1.1.2.1.6.POS adslAtucCurrStatus
ADSL .1.3.6.1.2.1.10.94.1.1.7.1.1.POS adslAturPerfLofs
ADSL .1.3.6.1.2.1.10.94.1.1.6.1.1.POS adslAtucPerfLofs
ADSL .1.3.6.1.2.1.10.94.1.1.7.1.2.POS adslAturPerfLoss
ADSL .1.3.6.1.2.1.10.94.1.1.6.1.2.POS adslAtucPerfLoss
ADSL .1.3.6.1.2.1.10.94.1.1.7.1.3.POS adslAturPerfLprs
ADSL .1.3.6.1.2.1.10.94.1.1.6.1.4.POS adslAtucPerfLprs
ADSL .1.3.6.1.2.1.10.94.1.1.11.1.4.POS adslAturChanUncorrectBlks
ADSL .1.3.6.1.2.1.10.94.1.1.10.1.4.POS adslatucChanUncorrectBlks
ADSL .1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.1.POS adslLineStatusMode
ADSL .1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.3.POS adslLineStatusAturInp
ADSL .1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.4.POS adslLineStatusAtucInp
[lbl@dm ~/zyxel-dslam-miner/trunk]$ 
[lbl@dm ~/zyxel-dslam-miner/trunk]$ ADSL_rename=`cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done | sed 's/ /sed /'` ; echo $ADSL_rename
sed -e 's/.1.3.6.1.2.1.2.2.1.7.POS/ifAdminStatus/' -e 's/.1.3.6.1.2.1.2.2.1.8.POS/ifOperStatus/' -e 's/.1.3.6.1.2.1.10.94.1.1.1.1.4.POS/adslLineConfProfile/' -e 's/.1.3.6.1.2.1.10.94.1.1.3.1.8.POS/adslAturCurrAttainableRate/' -e 's/.1.3.6.1.2.1.10.94.1.1.2.1.8.POS/adslAtucCurrAttainableRate/' -e 's/.1.3.6.1.2.1.10.94.1.1.5.1.2.POS/adslAturChanCurrTxRate/' -e 's/.1.3.6.1.2.1.10.94.1.1.4.1.2.POS/adslAtucChanCurrTxRate/' -e 's/.1.3.6.1.2.1.10.94.1.1.3.1.4.POS/adslAturCurrSnrMgn/' -e 's/.1.3.6.1.2.1.10.94.1.1.2.1.4.POS/adslAtucCurrSnrMgn/' -e 's/.1.3.6.1.2.1.10.94.1.1.3.1.5.POS/adslAturCurrAtn/' -e 's/.1.3.6.1.2.1.10.94.1.1.2.1.5.POS/adslAtucCurrAtn/' -e 's/.1.3.6.1.2.1.10.94.1.1.3.1.7.POS/adslAturCurrOutputPwr/' -e 's/.1.3.6.1.2.1.10.94.1.1.2.1.7.POS/adslAtucCurrOutputPwr/' -e 's/.1.3.6.1.2.1.10.94.1.1.5.1.1.POS/adslAturChanInterleaveDelay/' -e 's/.1.3.6.1.2.1.10.94.1.1.4.1.1.POS/adslAtucChanInterleaveDelay/' -e 's/.1.3.6.1.2.1.10.94.1.1.11.1.3.POS/adslAturChanCorrectedBlks/' -e 's/.1.3.6.1.2.1.10.94.1.1.10.1.3.POS/adslAtucChanCorrectedBlks/' -e 's/.1.3.6.1.2.1.10.94.1.1.7.1.4.POS/adslAturPerfESs/' -e 's/.1.3.6.1.2.1.10.94.1.1.6.1.5.POS/adslAtucPerfESs/' -e 's/.1.3.6.1.2.1.10.94.1.1.6.1.6.POS/adslAtucPerfInits/' -e 's/.1.3.6.1.2.1.10.94.3.1.20.1.1.POS/adslAturPerfStatSesL/' -e 's/.1.3.6.1.2.1.10.94.3.1.18.1.3.POS/adslAtucPerfStatSesL/' -e 's/.1.3.6.1.2.1.10.94.3.1.18.1.4.POS/adslAtucPerfStatUasL/' -e 's/.1.3.6.1.2.1.10.94.3.1.20.1.2.POS/adslAturPerfStatUasL/' -e 's/.1.3.6.1.2.1.10.94.1.1.3.1.6.POS/adslAturCurrStatus/' -e 's/.1.3.6.1.2.1.10.94.1.1.2.1.6.POS/adslAtucCurrStatus/' -e 's/.1.3.6.1.2.1.10.94.1.1.7.1.1.POS/adslAturPerfLofs/' -e 's/.1.3.6.1.2.1.10.94.1.1.6.1.1.POS/adslAtucPerfLofs/' -e 's/.1.3.6.1.2.1.10.94.1.1.7.1.2.POS/adslAturPerfLoss/' -e 's/.1.3.6.1.2.1.10.94.1.1.6.1.2.POS/adslAtucPerfLoss/' -e 's/.1.3.6.1.2.1.10.94.1.1.7.1.3.POS/adslAturPerfLprs/' -e 's/.1.3.6.1.2.1.10.94.1.1.6.1.4.POS/adslAtucPerfLprs/' -e 's/.1.3.6.1.2.1.10.94.1.1.11.1.4.POS/adslAturChanUncorrectBlks/' -e 's/.1.3.6.1.2.1.10.94.1.1.10.1.4.POS/adslatucChanUncorrectBlks/' -e 's/.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.1.POS/adslLineStatusMode/' -e 's/.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.3.POS/adslLineStatusAturInp/' -e 's/.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.4.POS/adslLineStatusAtucInp/'
[lbl@dm ~/zyxel-dslam-miner/trunk]$ 
[lbl@dm ~/zyxel-dslam-miner/trunk]$ tail -n 1 log.log 
'2009-10-28 12:39:55','ds1-van','1048','ADSL','.1.3.6.1.2.1.2.2.1.7.POS=up','.1.3.6.1.2.1.2.2.1.8.POS=up','.1.3.6.1.2.1.10.94.1.1.1.1.4.POS="2048d512u"','.1.3.6.1.2.1.10.94.1.1.3.1.8.POS=1129000','.1.3.6.1.2.1.10.94.1.1.2.1.8.POS=22192000','.1.3.6.1.2.1.10.94.1.1.5.1.2.POS=510000','.1.3.6.1.2.1.10.94.1.1.4.1.2.POS=2044000','.1.3.6.1.2.1.10.94.1.1.3.1.4.POS=310','.1.3.6.1.2.1.10.94.1.1.2.1.4.POS=234','.1.3.6.1.2.1.10.94.1.1.3.1.5.POS=245','.1.3.6.1.2.1.10.94.1.1.2.1.5.POS=121','.1.3.6.1.2.1.10.94.1.1.3.1.7.POS=122','.1.3.6.1.2.1.10.94.1.1.2.1.7.POS=173','.1.3.6.1.2.1.10.94.1.1.5.1.1.POS=10','.1.3.6.1.2.1.10.94.1.1.4.1.1.POS=7','.1.3.6.1.2.1.10.94.1.1.11.1.3.POS=4047','.1.3.6.1.2.1.10.94.1.1.10.1.3.POS=61','.1.3.6.1.2.1.10.94.1.1.7.1.4.POS=125','.1.3.6.1.2.1.10.94.1.1.6.1.5.POS=102','.1.3.6.1.2.1.10.94.1.1.6.1.6.POS=12','.1.3.6.1.2.1.10.94.3.1.20.1.1.POS=0','.1.3.6.1.2.1.10.94.3.1.18.1.3.POS=102','.1.3.6.1.2.1.10.94.3.1.18.1.4.POS=876','.1.3.6.1.2.1.10.94.3.1.20.1.2.POS=876','.1.3.6.1.2.1.10.94.1.1.3.1.6.POS="80 "','.1.3.6.1.2.1.10.94.1.1.2.1.6.POS="80 00 "','.1.3.6.1.2.1.10.94.1.1.7.1.1.POS=0','.1.3.6.1.2.1.10.94.1.1.6.1.1.POS=11','.1.3.6.1.2.1.10.94.1.1.7.1.2.POS=0','.1.3.6.1.2.1.10.94.1.1.6.1.2.POS=10','.1.3.6.1.2.1.10.94.1.1.7.1.3.POS=1','.1.3.6.1.2.1.10.94.1.1.6.1.4.POS=0','.1.3.6.1.2.1.10.94.1.1.11.1.4.POS=0','.1.3.6.1.2.1.10.94.1.1.10.1.4.POS=20','.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.1.POS=6','.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.3.POS=32','.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.4.POS=5'
[lbl@dm ~/zyxel-dslam-miner/trunk]$ 
[lbl@dm ~/zyxel-dslam-miner/trunk]$ ADSL_rename=`cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done | sed 's/ /sed /'` ; tail -n 1 log.log | $ADSL_rename
sed: 1: "'s/.1.3.6.1.2.1.2.2.1.7 ...": invalid command code '
[lbl@dm ~/zyxel-dslam-miner/trunk]$

sed complains about the "' ... but i cant seem to solve it.

/lbl
 
The first part of your command (1) produces one single long line with this:

Code:
 -e 's/.1.3.6.1.2.1.2.2.1.7.POS/ifAdminStatus/' -e 's/.1.3.6.1.2.1.2.2.1.8.POS/ifOperStatus/' -e 's/.1.3.6.1.2.1.10.94.1.1.1.1.4.POS/adslLineConfProfile/' etc etc.

Is that what you want to feed to sed?

(1)
Code:
cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done
 
This part seems to work


Code:
cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done | sed 's/ /sed /'
 
The point is to take all the oid's and name's and roll em into one string thats then agruments to sed, then in the end of the rolling i "sed 's/^ /sed/'" to produce a complete sed line.

Then when i run "tail -n 1 log.log | $ADSL_rename" i woud expect bash to replace $ADSL_rename with the "sed -e 's/.1.3.6.1.2.1.2.2.1.7.POS/ifAdminStatus/' -e 's/.1.3.6.1 ........"

But for some reason inside this it seems to get an extra " infront so sed gets confused ...

I hope that cleared it up.

/lbl
 
Smaller example.

Code:
[lbl@atom0 ~]$ cat buhu 
1234 yeha
4321 ehay
[lbl@atom0 ~]$ cat result 
line: 1234=1 4321=1
[lbl@atom0 ~]$ rename=`cat buhu | while read num name ; do printf " -e \'s/$num/$name/\'" ; done | sed 's/ /sed /'` ; echo $rename
sed -e 's/1234/yeha/' -e 's/4321/ehay/'
[lbl@atom0 ~]$ rename=`cat buhu | while read num name ; do printf " -e \'s/$num/$name/\'" ; done | sed 's/ /sed /'` ; cat result | $rename
sed: 1: "'s/1234/yeha/'
": invalid command code '
[lbl@atom0 ~]$

This is basicly the issue.

But this works

Code:
[lbl@atom0 ~]$ cat result | sed -e 's/1234/yeha/' -e 's/4321/ehay/'
line: yeha=1 ehay=1
[lbl@atom0 ~]$

/lbl
 
I think the shell gets confused a bit too much here. Try:

Code:
cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done | sed 's/ /sed /' > /tmp/adsl_rename
chmod 500 /tmp/adsl_rename
tail -n 1 log.log | /tmp/adsl_rename
 
Code:
lbl@dm ~/zyxel-dslam-miner/trunk]$ tail -n 1 log.log 
'2009-10-28 12:39:55','ds1-van','1048','ADSL','.1.3.6.1.2.1.2.2.1.7.POS=up','.1.3.6.1.2.1.2.2.1.8.POS=up','.1.3.6.1.2.1.10.94.1.1.1.1.4.POS="2048d512u"','.1.3.6.1.2.1.10.94.1.1.3.1.8.POS=1129000','.1.3.6.1.2.1.10.94.1.1.2.1.8.POS=22192000','.1.3.6.1.2.1.10.94.1.1.5.1.2.POS=510000','.1.3.6.1.2.1.10.94.1.1.4.1.2.POS=2044000','.1.3.6.1.2.1.10.94.1.1.3.1.4.POS=310','.1.3.6.1.2.1.10.94.1.1.2.1.4.POS=234','.1.3.6.1.2.1.10.94.1.1.3.1.5.POS=245','.1.3.6.1.2.1.10.94.1.1.2.1.5.POS=121','.1.3.6.1.2.1.10.94.1.1.3.1.7.POS=122','.1.3.6.1.2.1.10.94.1.1.2.1.7.POS=173','.1.3.6.1.2.1.10.94.1.1.5.1.1.POS=10','.1.3.6.1.2.1.10.94.1.1.4.1.1.POS=7','.1.3.6.1.2.1.10.94.1.1.11.1.3.POS=4047','.1.3.6.1.2.1.10.94.1.1.10.1.3.POS=61','.1.3.6.1.2.1.10.94.1.1.7.1.4.POS=125','.1.3.6.1.2.1.10.94.1.1.6.1.5.POS=102','.1.3.6.1.2.1.10.94.1.1.6.1.6.POS=12','.1.3.6.1.2.1.10.94.3.1.20.1.1.POS=0','.1.3.6.1.2.1.10.94.3.1.18.1.3.POS=102','.1.3.6.1.2.1.10.94.3.1.18.1.4.POS=876','.1.3.6.1.2.1.10.94.3.1.20.1.2.POS=876','.1.3.6.1.2.1.10.94.1.1.3.1.6.POS="80 "','.1.3.6.1.2.1.10.94.1.1.2.1.6.POS="80 00 "','.1.3.6.1.2.1.10.94.1.1.7.1.1.POS=0','.1.3.6.1.2.1.10.94.1.1.6.1.1.POS=11','.1.3.6.1.2.1.10.94.1.1.7.1.2.POS=0','.1.3.6.1.2.1.10.94.1.1.6.1.2.POS=10','.1.3.6.1.2.1.10.94.1.1.7.1.3.POS=1','.1.3.6.1.2.1.10.94.1.1.6.1.4.POS=0','.1.3.6.1.2.1.10.94.1.1.11.1.4.POS=0','.1.3.6.1.2.1.10.94.1.1.10.1.4.POS=20','.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.1.POS=6','.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.3.POS=32','.1.3.6.1.4.1.890.1.5.13.5.8.2.4.1.4.POS=5'
[lbl@dm ~/zyxel-dslam-miner/trunk]$

Thats what the tail -n 1 log.log is producing ...

Code:
[lbl@atom0 ~]$ cat result 
line: 1234=1 4321=1
[lbl@atom0 ~]$

... in the simple example.

Code:
[lbl@dm ~/zyxel-dslam-miner/trunk]$ cat test.bash 
#!/usr/local/bin/bash

while read line
	do
		echo "$line" | `cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done | sed 's/ /sed /'`
done
[lbl@dm ~/zyxel-dslam-miner/trunk]$ tail -n 1 log.log | ./test.bash 
sed: 1: "'s/.1.3.6.1.2.1.2.2.1.7 ...": invalid command code '
[lbl@dm ~/zyxel-dslam-miner/trunk]$

You have to refacture it since it wont work in a script file.

This is more or less exatly the same example as before.

More ideas ?

/lbl
 
Try the script I posted in my previous post? I changed that post while you were typing the reply, I think.
 
Code:
[lbl@dm ~/zyxel-dslam-miner/trunk]$ cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done | sed 's/ /sed /' > sed-test.bash ; chmod u+x sed-test.bash
[lbl@dm ~/zyxel-dslam-miner/trunk]$ tail -n 1 log.log | ./sed-test.bash 
'2009-10-28 12:39:55','ds1-van','1048','ADSL','ifAdminStatus=up','ifOperStatus=up','adslLineConfProfile="2048d512u"','adslAturCurrAttainableRate=1129000','adslAtucCurrAttainableRate=22192000','adslAturChanCurrTxRate=510000','adslAtucChanCurrTxRate=2044000','adslAturCurrSnrMgn=310','adslAtucCurrSnrMgn=234','adslAturCurrAtn=245','adslAtucCurrAtn=121','adslAturCurrOutputPwr=122','adslAtucCurrOutputPwr=173','adslAturChanInterleaveDelay=10','adslAtucChanInterleaveDelay=7','adslAturChanCorrectedBlks=4047','adslAtucChanCorrectedBlks=61','adslAturPerfESs=125','adslAtucPerfESs=102','adslAtucPerfInits=12','adslAturPerfStatSesL=0','adslAtucPerfStatSesL=102','adslAtucPerfStatUasL=876','adslAturPerfStatUasL=876','adslAturCurrStatus="80 "','adslAtucCurrStatus="80 00 "','adslAturPerfLofs=0','adslAtucPerfLofs=11','adslAturPerfLoss=0','adslAtucPerfLoss=10','adslAturPerfLprs=1','adslAtucPerfLprs=0','adslAturChanUncorrectBlks=0','adslatucChanUncorrectBlks=20','adslLineStatusMode=6','adslLineStatusAturInp=32','adslLineStatusAtucInp=5'
[lbl@dm ~/zyxel-dslam-miner/trunk]$

Yep this works ... but its not efficient in any way ... you have to open a script and sed over and over again.

The problem is that the log.log file can contain millions of lines that needs to be renamed.

So i have to prebuild the sed command and put it in the end of each print to the log.log file in the log.log file producing script.

That way i can preserve a few millions hits to sed-test.bash.

More ideas ?

/lbl
 
Whether you use a variable or a script, you're still calling sed on the system ... Put the script on a RAM disk ;)
 
he ... true it will work but its not a good way to do it.

Scripts that generate scripts the scripts needs to run just seems odd ... hehe

I guess the core problem is understanding how bash inserts variabels in the command chain.

Code:
[lbl@atom0 ~]$ cat t.bash
#!/usr/local/bin/bash

sedline="sed -e 's/1234/yeha/' -e 's/4321/ahey/'"

echo "line: 1234=1 4321=1" | $sedline
[lbl@atom0 ~]$ ./t.bash 
sed: 1: "'s/1234/yeha/'
": invalid command code '
[lbl@atom0 ~]$

No debug.

Code:
[lbl@atom0 ~]$ cat t.bash 
#!/usr/local/bin/bash -x

sedline="sed -e 's/1234/yeha/' -e 's/4321/ahey/'"

echo "line: 1234=1 4321=1" | $sedline
[lbl@atom0 ~]$ ./t.bash 
+ sedline='sed -e '\''s/1234/yeha/'\'' -e '\''s/4321/ahey/'\'''
+ echo 'line: 1234=1 4321=1'
+ sed -e ''\''s/1234/yeha/'\''' -e ''\''s/4321/ahey/'\'''
sed: 1: "'s/1234/yeha/'
": invalid command code '
[lbl@atom0 ~]$

With debug.

it seems that bash actualt adds more ' around the insert ... still not quite shure how to fix it tho ...

/lbl
 
How often does oids.conf change? You only have to generate the final script (the one that the tail pipes into) if and when oids.conf changes, right? You can use that script indefinitely if oids.conf never changes, and putting it on a ram disk should give you minimal overhead. Or you could put the script itself in memory.

Code:
echo 'while read line; do' > /tmp/adsl_rename
echo 'echo ${line} | \' >> /tmp/adsl_rename
cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done | sed 's/ /sed /' >> /tmp/adsl_rename
echo 'done' >> /tmp/adsl_rename
chmod 500 /tmp/adsl_rename

tail -n 1 -f log.log | /tmp/adsl_rename

This will just hang the script off of a continuous tail of log.log, and keep the entire process in RAM.
 
Code:
[lbl@atom0 ~]$ cat t.bash 
#!/usr/local/bin/bash -x

sedline='sed -e s/1234/yeha/ -e s/4321/ahey/'

echo "line: 1234=1 4321=1" | $sedline
[lbl@atom0 ~]$ ./t.bash 
+ sedline='sed -e s/1234/yeha/ -e s/4321/ahey/'
+ echo 'line: 1234=1 4321=1'
+ sed -e s/1234/yeha/ -e s/4321/ahey/
line: yeha=1 ahey=1
[lbl@atom0 ~]$

That was ok to fix ... but it still dosent resolv the problem.

Code:
[lbl@atom0 ~]$ cat t.bash 
#!/usr/local/bin/bash

echo "1234 yeha" > /tmp/T
echo "4321 ahey" >> /tmp/T
echo "1321 boby" >> /tmp/T

sedline="`cat /tmp/T | while read oid name ; do printf " -e \"s/$oid/$name/\"" ; done | sed 's/^/sed/'`"

echo "line: 1234=1 4321=1 1321=2" | $sedline
[lbl@atom0 ~]$ ./t.bash 
line: yeha=1 ahey=1 boby=2
[lbl@atom0 ~]$

This however seems to work ...

Code:
[lbl@dm ~/zyxel-dslam-miner/trunk]$ ADSL_rename="`cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \"s/$oid/$name/\"" ; done | sed 's/^/sed/'`" ; tail -n 1 log.log | $ADSL_rename
'2009-10-28 12:39:55','ds1-van','1048','ADSL','ifAdminStatus=up','ifOperStatus=up','adslLineConfProfile="2048d512u"','adslAturCurrAttainableRate=1129000','adslAtucCurrAttainableRate=22192000','adslAturChanCurrTxRate=510000','adslAtucChanCurrTxRate=2044000','adslAturCurrSnrMgn=310','adslAtucCurrSnrMgn=234','adslAturCurrAtn=245','adslAtucCurrAtn=121','adslAturCurrOutputPwr=122','adslAtucCurrOutputPwr=173','adslAturChanInterleaveDelay=10','adslAtucChanInterleaveDelay=7','adslAturChanCorrectedBlks=4047','adslAtucChanCorrectedBlks=61','adslAturPerfESs=125','adslAtucPerfESs=102','adslAtucPerfInits=12','adslAturPerfStatSesL=0','adslAtucPerfStatSesL=102','adslAtucPerfStatUasL=876','adslAturPerfStatUasL=876','adslAturCurrStatus="80 "','adslAtucCurrStatus="80 00 "','adslAturPerfLofs=0','adslAtucPerfLofs=11','adslAturPerfLoss=0','adslAtucPerfLoss=10','adslAturPerfLprs=1','adslAtucPerfLprs=0','adslAturChanUncorrectBlks=0','adslatucChanUncorrectBlks=20','adslLineStatusMode=6','adslLineStatusAturInp=32','adslLineStatusAtucInp=5'
[lbl@dm ~/zyxel-dslam-miner/trunk]$

And the real deal works aswell.

Well the oids.conf dosent change that offen ... so its not a big deal ...

I guess the problem is that i kinda want some clean code that dosent requiere a lot of different stuff to run.

In this case it also has to be fast inorder to make any sense ... to be honest this kind of job should be handled by perl or some other lang ... but i wanna prove that it actualy can be done in bash so ...

So to compare the 2 lines:
Code:
ADSL_rename=`cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \'s/$oid/$name/\'" ; done | sed 's/ /sed /'` ; tail -n 1 log.log | $ADSL_rename
ADSL_rename="`cat oids.conf | grep "ADSL" | while read type oid name ; do printf " -e \"s/$oid/$name/\"" ; done | sed 's/^/sed/'`" ; tail -n 1 log.log | $ADSL_rename

He ... the cap up is always remember " ... hehe

thanks for poking me around ... hehe

/lbl
 
Back
Top