I need to read first line of a file and match it with a text. If the text matches, I need to do certain operation.
Problem is if command is unable to compare the variable with the string.
file_content=$(head -1 ${file_name})
echo $file_content
if [[ $file_content = 'No new data' ]]; then
echo "Should come here"
fi
echo $file_content
if [ "${file_content}" = "No new data" ]; then
echo "Should come here"
fi
The if block is not working. I think the value that I am capturing in line 1 has some issues.
printf '%s\n' "$file_content" | sed -n l
output? – Stéphane Chazelas Apr 18 '17 at 10:14What is this \r$ at the end? How to fix this. – romil gaurav Apr 18 '17 at 10:31
\r
. Just follow the instructions in the duplicate. – terdon Apr 18 '17 at 10:32