shell - Printing "#include" or the Whole File if not Found Linux Command Line -


i trying figure out how search file example test.txt "#include" , print first instance of found. if not found want print out whole file. can first part grep "#include" test.txt | head -n 1 can't seem figure out how include second requirement.

grep -m 1 '#include' "$file" || cat "$file" 

you can control grep's output in many ways grep options.
grep exits non-success status if match not found.


Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -