Hi,

I wish to delete the last three lines of a file iteratively. I tried this in unix shell scripting but it is not working..

lines=$(wc -l < s27.cnf)
target=$((lines-2))
sed '$target,$lines d' s27.cnf > f2.cnf
mv f2.cnf s27.cnf

I am getting an error "sed: 1: "$target,$lines d": undefined label 'arget,$lines d'
So was not sure what to use.

I would appreciate help on this.

Single quotes disable substitution, so perhaps

sed "$target,$lines d" s27.cnf > f2.cnf
sed $target','$lines' d' s27.cnf > f2.cnf

Hey there,

You can also do it this way

sed -e :a -e '$d;N;2,3ba' -e 'P;D' s27.cnf >f2.cnf

Just change the 3 to hower many lines you want to delete from the bottom

Best wishes,

Mike

Thanks...it worked...

I appreciate the help

Your welcome, of course :)

Best wishes,

Mike