Bash check file for pattern
How do I write an if statement in Bash so that it executes only if the first line in a file matches or doesn't match a regex?
|
Do you mean something like this
Code:
if [[ "$(head -n1 file)" =~ RegEx ]];then Alternatively, Code:
read var < file |
Is it OK if the regex contains whitespace, are quotes still not needed?
|
Quote:
Code:
set -x |
If you use sh or older bash versions without [[ support, you can always use sed:
Code:
if sed -ne '1 { /pattern/ q0 } ; q1' file ; then Hope this helps, Nominal Animal |
All times are GMT -5. The time now is 06:03 PM. |