I have got this script here. It is supposed to run the loop by reading the file LineNumbers.file line by line (each contains a line number) and then accordingly replacing 0/0 with ./. in the BEFORE_File.txt. It works, but it takes only the very last line of the file LineNumbers.file, instead of the >100 entries.
I am not sure what I am doing wrong here. Can you please help me to get awk to read the LineNumbers.file line by line?
I have got it to work with sed -i "${line}s/0\/0/\.\/\./" "${myFileTmp}"
, but it was really slow on the >3GB large files that I have got. So I thought that awk would be a faster option.
Many thanks!
cat ./LineNumbers_TEMP/LineNumbers.file | while read line
do
myFileTmp=BEFORE_File.txt
awk -v var=${line} 'FNR==var { sub(/0\/0/, "\.\/\."); print }' "${myFileTmp}" > AFTER_File.txt
done
For example this is how the files look like:
cat ./LineNumbers_TEMP/LineNumbers.file
1
2
5
File.txt before script:
cat BEFORE_File.txt
0/0
0/0
0/1
0/1
0/0
0/0
0/0
This is how the file should look after running the script:
cat AFTER_File.txt
./.
./.
0/1
0/1
./.
0/0
0/0
At the moment I get only this:
./.
blabla 4858 ABC 0/0:4,3,2 0/1:4,3,2
. At the moment it would not work for me because of the exact line match. Thanks..I like the toothpick syndrome :D.
– P. HamB Apr 24 '20 at 07:08\<0/0\>
rather than^0/0$
.\<
and\>
matches word boundaries. On GNU systems, you may use\b
instead of these. The answer must be updated further if you expect to replace all0/0
on these lines, but this is not currently what the question asks about. Always ask about exactly what you need. Update the question if you have further requirements (I won't update my answer as it would not be in line with the question otherwise). – Kusalananda Apr 24 '20 at 07:12sed 's#.*#&s,0/0,./.,#' LineNumbers.file | sed -f /dev/stdin BEFORE_File.txt >AFTER_File.txt
Many thanks for the help. Very much appreciated. – P. HamB Apr 24 '20 at 07:31\<0/0\>
or\b0/0\b
there if you don't want to replace10/0
with1./.
. – Kusalananda Apr 24 '20 at 07:33