Acabei de escrever e testar no MacOS High Sierra:
#!/bin/sh
for fl in *.xml
do
filename=$(echo $fl | cut -f 1 -d '.' | sed 's/_DANY$//')
sed -i .orig '1a\
<media:content url="'$filename'.mpg" type="video/mpg" expression="full" /> \
' $fl
done
ls *.xml search in current directory
-i .orig backup of original files with suffix
'1a ..' insert into second line
O BSD sed
no MacOS tem várias diferenças do GNU sed
, portanto, a seguinte expressão deve ser escrita em linhas separadas:
'1a \ # backslash and newline
some text'
O símbolo Newline \n
não é reconhecido, então você deve escrever:
'1a \
some text # newline here
'
em vez de:
'1a \
some text\n'
Uso:
yurijs-MacBook-Pro:sed yurij$ cat *.xml
<description>Entrepreneur James overcame unconscionable childhood abuse before the sins of his past came back to haunt him.</description>
<media:rating>TV-14</media:rating>
<description>Entrepreneur James overcame unconscionable childhood abuse before the sins of his past came back to haunt him.</description>
<media:rating>TV-14</media:rating>
yurijs-MacBook-Pro:sed yurij$ ./cli
yurijs-MacBook-Pro:sed yurij$ cat *.xml
<description>Entrepreneur James overcame unconscionable childhood abuse before the sins of his past came back to haunt him.</description>
<media:content url="24ToLife_AFamilyDivided_191045.mpg" type="video/mpg" expression="full" />
<media:rating>TV-14</media:rating>
<description>Entrepreneur James overcame unconscionable childhood abuse before the sins of his past came back to haunt him.</description>
<media:content url="tt.mpg" type="video/mpg" expression="full" />
<media:rating>TV-14</media:rating>