'How to run grep with while loop in shell script?
I'm trying to make shell script that counts 9 letters words consisted of A, G, C, T in B.txt.
First, 9bp_cases.txt contains
AAAAAAAAA
AAAAAAAAG
AAAAAAAAC
AAAAAAAAT
AAAAAAAGA
AAAAAAAGG
AAAAAAAGC
...
//#!/bin/bash
file=/Dataset/4.synTF/2.Sequence/9bp_cases.txt
# CSV 파일이 존재하지 않으면 종료
if [ ! -f "$file" ]; then
echo "CSV 파일이 존재하지 않습니다: $file" >&2
exit 1
fi
cat 9bp_cases.txt | while read line;
do
echo $line
grep -i -o $line B.txt | wc -w
done
The result is like this:
//AAAAAAAAA
0
AAAAAAAAG
0
AAAAAAAAC
0
AAAAAAAAT
0
AAAAAAAGA
0
None of the words is counted correctly. However, when I run the simple code, it returns result well.
grep -i -o AAAAAAAA B.txt | wc -w
33410
I guess $line after grep is not recognized by the command grep. Can you please help me?
Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|