I have a .txt file with 71 lines and I have another 12 set of files(file1 to file12). I want to copy first 5 lines from .txt file to file1 on specific line numbers similarly next 5 lines from .txt to file2 again on specific line numbers and so on.
This is my current code:
n = 1
sed -i '52,56d' $dumpfile
awk'{print $'"$n"',$'"$n+1"',$'"$n+2"',$'"$n+3"'}' sample.txt > $dumpfile
n=$(($n + 1))
In $dumpfile
I have put my 12 files.
Sample file (12files; file1, file2...)
...........
................
..............
abc = 4,1,3
def = 1,2,6
dfg = 28,36,4
tyu = 68,47,6
rty = 65,6,97
file (sample.txt)
abc = 1,2,3
def = 4,5,6
dfg = 2,3,4
tyu = 8,7,6
rty = 5,6,7
abc = 21,2,32
def = 64,53,6
dfg = 28,3,4
tyu = 18,75,6
rty = 5,63,75
...........
...........
I want to replace these five lines of (file1... file12) with five lines of sample.txt file. Line number of lines to be replaced in file1 to file12 are same in all the 12 files, where as in sample.txt file first set of 5 lines will go in file1, second set of 5 lines will go in file2 and so on upto file12.
split -l 5 input_file
would be your best bet, although presumably you have been told to use awk as a learning exercise. If that's the case, I agree with @fedorqui, you really need to make an attempt yourself. – Tom Fenech