pythonbeginer pythonbeginer - 2 years ago 133
Linux Question

changing a specific field as per file name

I have 20 files named as nxt_bas_01.txt, nxt_bas_02.txt ... nxt_bas_20.txt and at all the files at line nr.5 i have the same text

TITLE / nxt_bas_01
now i need to change only at line nr.5 as per my file name, i tried with sed -i unsuccessfully, please have a look at my simple code and share your suggestions,

while [ "$num" -lt `expr $till + 01 ` ]
sed -i '5s/.*/TITLE / nxt_bas_01/' nxt_bas_$num.txt
num=`expr $num + 1 `

Answer Source

Try this :

for num in {01..20}; do
   sed -i "5s/.*/TITLE \/ nxt_bas_$num/" nxt_bas_$num.txt

Not tested but it should do the trick.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download