I am currently trying to evaluate txt-files in a directory using bash. I want to know if the third line of the txt-file matches a certain string. The file starts with two empty lines, then the target string. I tested the following one liner:
if [[ $(head -n 3 a_txt_file.txt) == "target_string" ]]; then echo yes; else echo no; fi
I can imagine that since head -n 3
also prints out the two empty lines, I have to add them to the if condition. But "\n\ntarget_string"
and "\n\ntarget_string\n"
also don't work.
How would one do this correctly (And I guess it can be done more elegantly as well)?