How do I inject the lines from one text file into another file at a specific line number?
Ive seen a few solutions on the net, none of which have worked. 
Cheers
Si
How do I inject the lines from one text file into another file at a specific line number?
Ive seen a few solutions on the net, none of which have worked. 
Cheers
Si
Sample example....
$ cat file1
line 1
line 2
line 3
line 4
$ cat file2
123
456
$ sed '2 r file2' file1
line 1
line 2
123
456
line 3
line 4
The above code will insert all the lines from file2 to file1 after 2nd line....
Post a sample input and output using code tags if you are not convinced....
A code snippet:
....
echo "" > $TMP_OUT
echo "LABEL $HOST $BUILD" >> $TMP_OUT
echo "MENU LABEL $HOST $BUILD" >> $TMP_OUT
echo "KERNEL vmlinuz-$BUILD" >> $TMP_OUT
echo "APPEND initrd=initrd-$BUILD.img method=$SERVER/$BUILD ksdevice=eth0 ksfile=$SERVER/files/$KSFILE noipv6" >> $TMP_OUT
sed '2 r $TMP_OUT' temp.menu
....
As you can see, I am trying to insert the contents of $TMP_OUT into temp.menu. $TMP_OUT is created perfectly each time. temp.menu is not.
Ive tried something like:
sed '2 r $TMP_OUT' temp.menu > temp1.menu
Again, didnt work. 
Cheers
Simon
small change..
Try now this should work..
sed "2 r $TMP_OUT" temp.menu > temp1.menu
Thanks
SHa
This still does not work. temp1.menu is blank.
I m getting the correct answer
see my below code..
$ cat file1
1 2 3 4 abcded
2 4 5 1 bcdef
5 1 2 3 enfjslj
2 3 1 5 fasfjdls
$ cat file2
BAW
BRITISH AIRWAYS
RYR
RYAN AIR
TMP_OUT=`echo "file1"`
OUTPUT:
$ sed "2 r $TMP_OUT" file2
BAW
BRITISH AIRWAYS
1 2 3 4 abcded
2 4 5 1 bcdef
5 1 2 3 enfjslj
2 3 1 5 fasfjdls
RYR
RYAN AIR
Hope this makes sence...
Thanks
SHa