Home » Questions » Computers [ Ask a new question ]

Unix: How to check the existence of a tag at the beginning of each file before insertion?

Unix: How to check the existence of a tag at the beginning of each file before insertion?

The question is related to the question "Unix: Add a Tag to the beginning of each file?".

Asked by: Guest | Views: 245
Total answers/comments: 2
Guest [Entry]

head -n1 file | grep -q "^<?php" || sed -i "1s/^/<?php /" file
Guest [Entry]

"You want || (OR). If the left hand is true, it will not bother with the right hand. e.g.

test ""$(grep PATTERN FILE)"" || sed COMMAND FILE"