In the bash
below the out put of a process is written to input
. What I am trying to do is read each line in the input
and verify/check it for specific text (there are always 6 lines for each file and the specific text for each line is in the description). There will always be 6 lines in each specific file in input
, however the file number can vary. In this example there are 3 specific files (each color block is a file with 6 lines), but the next time there may only be two. If each line in the file is a match to description then the file is verified/good, but if it does not then the file is not.
I hope the below is a start and have commented each line. Thank you :).
input
Start import validation creation: Wed May 17 06:55:34 CDT 2017
/home/cmccabe/Desktop/validate/file1.txt found expected header
/home/cmccabe/Desktop/validate/file1.txt found expected order of fields
/home/cmccabe/Desktop/validate/file1.txt R_Index is a number
/home/cmccabe/Desktop/validate/file1.txt PopFreqMax is valid
/home/cmccabe/Desktop/validate/file1.txt Quality is a character
/home/cmccabe/Desktop/validate/file1.txt HGMD and Sanger are valid
/home/cmccabe/Desktop/validate/file2.txt found expected header
/home/cmccabe/Desktop/validate/file2.txt found expected order of fields
/home/cmccabe/Desktop/validate/file2.txt R_Index is a number
/home/cmccabe/Desktop/validate/file2.txt PopFreqMax is valid
/home/cmccabe/Desktop/validate/file2.txt Quality is a character
/home/cmccabe/Desktop/validate/file2.txt HGMD and Sanger are valid
/home/cmccabe/Desktop/validate/file3.txt found expected header
/home/cmccabe/Desktop/validate/file3.txt found expected order of fields
/home/cmccabe/Desktop/validate/file3.txt R_Index is a number
/home/cmccabe/Desktop/validate/file3.txt PopFreqMax is valid
/home/cmccabe/Desktop/validate/file3.txt Quality is a character
/home/cmccabe/Desktop/validate/file3.txt HGMD and Sanger are valid
End import validation creation: Wed May 17 06:55:34 CDT 2017
#!/bin/bash
while read line; do # read each line in input
if echo "$line" | grep -q "Found expected header"; then echo "LINE IS GOOD" # read line 1
if echo "$line" | grep -q "Found expected order of fields"; then echo "LINE IS GOOD" # read line 2
if echo "$line" | grep -q "R_Index is a number"; then echo "LINE IS GOOD" # read line 3
if echo "$line" | grep -q "PopFreqMax is valid"; then echo "LINE IS GOOD" # read line 4
if echo "$line" | grep -q "Quality is a character"; then echo "LINE IS GOOD" # read line 5
if echo "$line" | grep -q "HGMD and Sanger are valid"; then echo "LINE IS GOOD" # read line 6
fi
done < file
file="home/cmccabe/Desktop/validate/input" # define path to input
string="LINE IS GOOD" # define string to look for in each line
count=$(grep -c "$string" "$file") # count string occurences
if [[ count -gt 6 ]]; then # if count = 6
echo "$string has occurred 6 times" # string is in each file x times
echo "FILENAME is verified" # specific file is verified or good
fi
else
echo "FILENAME not verified" # specific file not verified
fi
Description
1="Found expected header"
2="Found expected order of fields"
3="R_Index is a number"
4="PopFreqMax is valid"
5="Quality is a character"
6="HGMD and Sanger are valid"