cancel
Showing results for 
Search instead for 
Did you mean: 

SED 4.x broken?

Michael Williams_6
Trusted Contributor

SED 4.x broken?

Hello all, I've been trying to port a script of mine from SLES8 to SLES9, been pretty plain sailing so far as there aren't a great deal of differences, however I've just found a real show stopper, I'd like to know if anyone has the same problem to find out who to raise it with!

My SLES8 box runs sed 3.02.80.
My SLES9 box runs sed 4.0.9.

My script tries to identify what the config file for snmp is by checking the cmdline for it in the proc filesystem. The line is this:

SNMP_PID=`cat /var/run/snmpd.pid`
SNMP_CONFIG=`sed -e 's/^.*-c//' -e 's/-r.*$//' /proc/$SNMP_PID/cmdline`

However, use of the ^ & $ don't do anything in SLES9, but in SLES8, it'll strip out everthing before the -c and strip out everything after -r leaving me with the config file for snmp.

Does anyone else have this problem with sed on their systems? Are you all able to use ^ & $? I've tried the sed statement with single and double quotes with no difference...

I'm lost!
4 REPLIES
Johannes Krackowizer_1
Valued Contributor

Re: SED 4.x broken?

hi michael,

sorry i'm not very good with sed but i have tried your cmdline and it doesn't work on my fedora core 2 (sed 4.0.8).

but i have a workaround for you (i hope you can read it, it's not very nice without tabs):

TEMP_PAR_FILE="/tmp/GetSnmpConfigFile.$$"
NEXT="false"
SNMP_PID='/var/run/snmpd.pid'

rm -f $TEMP_PAR_FILE

for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30; do
awk -F '\00' {" print \$$i "} /proc/$SNMP_PID/cmdline >> $TEMP_PAR_FILE
done

for i in `cat $TEMP_PAR_FILE` do
if [ $NEXT == 'true' ]; then
SNMP_CONFIG="$i"
NEXT="false"
fi

if [ $i == '-c' ]; then
NEXT="true"
fi
done

rm -f $TEMP_PAR_FILE

echo $SNMP_CONFIG
"First off, I'd suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it's a great symbolic gesture." (Linus Torvalds)
Michael Williams_6
Trusted Contributor

Re: SED 4.x broken?

Hi there!

Thank you very much for your suggestion of a work-around!

Unfortunately while sed isn't working with the ^ & $, perl does, so I have a workaround already with perl:

perl -p -e "s/^.*-c//; s/-r.*$//" cmdline

I just want to see if this is a sed issue or a SuSE issue. I see that as you have the same problem, I'm guessing the programmers have intentionally removed this functionality...

But why?!!
Gregory Fruth
Esteemed Contributor

Re: SED 4.x broken?

Try escaping the minus signs. Perhaps sed
4.x is interpreting them as metacharacters.
Michael Williams_6
Trusted Contributor

Re: SED 4.x broken?

My good man, I so thought you had it then...

Only that didn't work either :-(