Hello,
I have two files. File1 is normal txt file and File2 contains list of line numbers.
e.g. File2:
3
6
9
.....
I need to replace a character in File1 in lines (taken from File2). For that I am using a "for" loop:
for i in $(cat File2)
do
sed "$i s/Y/N/" File1
done
but my files contain million numbers and for loop is taking a long time. can I use a faster approach?
Thanks......
You can try another way of reading "File2":
while read i; do
sed "$i s/Y/N/" File1
done < File2
I already tried but its slower than what I need....
I am trying to create a data file, which will look sonething like:
sed "3;6;9........ s/Y/N/" File1 (by running a for/while loop)
and then will execute this file..... hopefully this wud be faster....
awk 'NR == FNR {
nr[$1]; next
}
NR in nr {
sub(/Y/, "N")
}1' file2 file1