I am writing a ksh script. I have a pair of html files in a directory and I need to check whether or not the files contain one of two strings (the strings are mutually exclusive). I then rename the files based on which of the two strings they contain.
When testing I was able to use the following code on .txt
files, but the functionality no longer works when testing for the strings in .html
files:
outageString='Scheduled Outage List'
jobString='Scheduled Job List'
for file in `ls -1t $fileNameFormat | head -n 2`
do
if grep -xq "$outageString" "$file"; then
mv "$file" "$outageFileName"
elif grep -xq "$jobString" "$file"; then
mv "$file" "$jobFileName"
fi
done
Note: I have tested the ls
command above independently and it returns the appropriate files.
File Content:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>
OUS: Scheduled Outage List
</title>
</head>
<body>
<h3>
OUS: Scheduled Outage List
</h3>
.
.
.
Q: Does anyone have any insight as to why grep
is not returning the appropriate value when searching for the strings in the two files(i.e., why grep
does not recognize that the string exists in the file)?
Similar Question: How to test if string exists in file with Bash shell?