Length=$(cat Final.txt|wc -l)
echo $Length
sed -i '1 i\<records>$(echo $Length)</records>' Final.txt
I need to the add the line XXX where XXX should be the variable which represents the no.of lines.I have tried the above code and other combinations.None of them seems to work.
echo '$Length'
andecho "$Length"
. (Besides, the command substitution andecho
in thesed
command are unnecessary). shellcheck.net would actually tell you both of those. – ilkkachu Mar 08 '18 at 09:23