I need to add PHP tags surrounding a file. It's easy to append them using
find . -exec echo "?>" >> '{}' \;
but how can I prepend the tag <?php?
|
I need to add PHP tags surrounding a file. It's easy to append them using
but how can I prepend the tag |
||||
|
|
sed -i "1s/^/<?php /" file (The |
|||||||||||||||
|
|
You could use an
awk '{if(NR==1) printf "%s%s","PREFIX",$0; else print $0}' testfile > newfile
Where |
|||
|
|
|
You can do that with a perl one-liner:
The
Update: As indicated in the comments, you can choose to auto-generate a backup by using When updating a bunch of files, you could run the command with |
|||||||||||
|
|
I can't leave a comment yet, but to do it all in one step:
|
|||
|
|
|
|||||
|
|
An alternative to what you wrote for adding something to the end of every file in the directory (in
though I do like your |
|||||||
|