It would be easier and more portable with perl
:
perl -0777 -ni -e 'print qq(WEBVTT
Kind: captions
Language: eng
File Creation Date: 2023-08
$_)' -- *.vtt
sed
scripts consist of a series of [<address>[,<address>]] <command>
where <command>
s are single characters such as s
for substitute, b
for branch, i
for insert.
Here, the first non-whitespace character of your script is a W
. Not many sed
s have a W
command. Yours doesn't, but in those that have it such as GNU sed
, that will not do what you want.
Here it seems you want to insert some text at the beginning of the file. So you could use the i
sed
command with 1
as the address, meaning it will only be run on the first line (but beware it won't be run at all if the file is empty (has no line 1
)):
sed -i '' -e '1 i\
Kind: captions\
Language: eng\
File Creation Date: 2023-08' -- *.vtt
Here assuming the FreeBSD implementation of sed
which you seem to be using.
With the GNU implementation of sed
, that would have to be:
sed -si -e '1 i\
Kind: captions\
Language: eng\
File Creation Date: 2023-08' -- *.vtt
There, the backup suffix (here empty) must be affixed to the -i
options and -s
is needed for the line number to be reset between each file.
With GNU sed
, if you have the text to insert in a header
file, you can do:
sed -si -e '0 r header' -- *.vtt
(address 0
is a GNU extension and is only valid in address ranges and for the r
command; that still does not prepend the header
to empty files)
sed
instructions are not valid, but in order to help you we need to understand your intentions. Also, you might want to start without a loop to make it simpler. – aviro Sep 20 '23 at 17:00sed
out there and telling us your operating system will tell us which one you are likely to use and also what other tools might be available. – terdon Sep 20 '23 at 17:41sed
issues, this is a duplicate of How to prepend multiple lines to a file – Kusalananda Sep 20 '23 at 17:59