I would like to delete all lines containing a certain string, as well as the next 3 lines.
I can use the sed command to do this easily when using a single string:
sed '/HISEQ:243:C9FH7ANXX:4:2202:4922:44902/,+3 d' ../input/infile.fq_1 > ../output/outfile.fq_1
The double quoted version also works:
sed "/HISEQ:243:C9FH7ANXX:4:2202:4922:44902/,+3 d" ../input/infile.fq_1 > ../output/outfile.fq_1
However, I would like to use many strings. Each string is a line in a text file named strings.txt, and I would like to match one string at a time, removing the lines that match in the infile as well as the next 3 each time, and writing the output to the outfile.
So I've tried:
cat strings.txt | while read LINE
do
sed '/$LINE/,+3 d' ../input/infile.fq_1 > ../output/outfile.fq_1
done
But the variable isn't recognized with single quotes. If I use double quotes:
cat strings.txt | while read LINE
do
sed "/$LINE/,+3 d" ../input/infile.fq_1 > ../output/outfile.fq_1
done
This doesn't work either.
I've also tried all kinds of variations, like using curly brackets or using both types of quotes:
cat strings.txt | while read LINE
do
sed '/'"$LINE"'/,+3 d' ../input/infile.fq_1 > ../output/outfile.fq_1
done
But nothing seems to work. Help would be much appreciated!
$LINE
doesn't contain any regex metacharacters or additional/
delimiters. What happens exactly (no lines get deleted? too many lines get deleted?). Can you give us a minimal working example (strings.txt
andinfile.fq_1
files)?