Passing variables to an input file

Hi All,

I have to insert 2 values to a text file in specific places. I have been able to extract each variable value via a script but am not able to send these variable values to the text file.

Pasted is the script for extracting the variable values:

for i in `ls -1`                                            
do                                                          
s=`awk 'END{print NR}' $i`                                  
dur=`awk '{s+=substr($0,85,9)}END{printf "%09d\n", s } ' $i`
length=`printf "%036d %s" $s`                               
echo -en $length"\t\t$dur""\n"                              
done

After getting the values, I need to insert them into the text file pasted below mantaining the space length between the strings:

$length          $dur              130219235419  00000000                00000000000000   00000000000000000000000000                000000000                           0000000000                    000000000000000                00000000000000000000000000000000000000000000000000                                    0

Any idea how we can do it. Any help is appreciated a lot

You can modify your script..

for i in $(ls -1)
do
length=$(awk 'END{printf "%036d", NR}' $i)
dur=$(awk '{s+=substr($0,85,9)}END{printf "%09d\n", s } ' $i)
#Please read more about sed for inserting data into file.
done 
1 Like

Thanks. I looked up on sed and it worked great..thanks again