I have to substitute the content of lines from a file with another line (in the same position number 3) in multiple files. The problem looks like the following:
Input1
file.list <- list("a","b","c","d")
file.list <- list("d","e","f","g")
file.list <- list("h","i","l","m")
Input2.file
library(data.table)
library(dplyr)
file.list <- list("z","g","h","s","i")
Input3.file
library(data.table)
library(dplyr)
file.list <- list("s","p","q","r","m")
Input4.file
library(data.table)
library(dplyr)
file.list <- list("x","k","s","e")
Output of Input2.file
library(data.table)
library(dplyr)
file.list <- list("a","b","c","d")
Output of Input3.file
library(data.table)
library(dplyr)
file.list <- list("d","e","f","g")
Output of Input4.file
library(data.table)
library(dplyr)
file.list <- list("h","i","l","m")
I have tried to do as follow:
filename='Input1'
for i in *.file; do #here i loop over the list of files
while read p $filename; do #here i loop over the lines of Input1 file
awk '{ if (NR == 3) print "$p"; else print $0}' $i > $i.test; ##here i substitute the line 1 in the files with the line that are in Input1 file
done;
done
Am doing something wrong because the script is stopping without giving me any message. What am doing wrong? Any Idea?
awk
command to a file. Why would you expect to see any messages?