Hello, I've got a similar problem. I want to add some lines before the ending of the <head>
tags. How can I do that?
Example.
<head>
<some website stuff here>
<My stuff>
<head>
I'd like to do that automatically with ftp. Is it possible to activate a sort of syncing in order to update changed files? And I'd also like to prevent adding <my stuff>
in files that already have <my stuff>
.
Thank you!
Please post your question in another thread.
FTP is very simple and stupid. It can't edit files. You could download them, edit them, and upload them back.
Yes, I know that ftp is stupid and it can't edit files. I was looking for a sort of ftp syncing solution for modified files, a bit like dropbox. But my main question was, and remains: I want to add some lines before the ending of the <head>
tags. How can I do that?
Example. HTML Code:
<head>
<some website stuff here>
<My stuff>
<head>
I'd also like to prevent adding <my stuff>
in files that already have <my stuff>
.
Thank you.
Split from This Thread.
Please use code tags for code,
```text
stuff
```
1 Like
Hmmm. Keep a line like <!-- MY HEADER -->
in your stuff so you can scan for it to tell if it's there. <!-- END MY HEADER -->
would also be good in case you need to remove it later.
OLDIFS="$IFS"
IFS="/"
N=0
find /path/to/files -type f | while read FILEPATH
do
set -- $FILEPATH # $1=path, $2=to, $3=files, $3=subdir, etc
shift 3 # Discard 'path', 'to', 'files'
DESTDIR="/home/username/public_html/"$* # /home/username/public_html/subdir/filename
grep "<!-- MY HEADER -->" "$FILEPATH" && continue
if [ ! -e "$NEWPATH" ] || [ "$FILEPATH" -nt "$NEWPATH" ]
then
awk -f newheader.awk header="/path/to/headerfile" "$FILEPATH" > "/tmp/$$-$N"
echo "put \"/tmp/$$-$N\" \"$NEWPATH\""
let N=N+1
fi
done > list-of-files-to-upload
ftp <<EOF
...
`cat list-of-files-to-upload`
...
EOF
rm -f /tmp/$$-*
I cannot guarantee that newhead.awk is bulletproof. Parsing XML is not trivial.
$ cat newhead.awk
BEGIN {
FS=">"
OFS=">"
RS="<"
ORS="<"
}
NR==1 { next } # The first "line" is blank when RS=<
/^[!?]/ { printf("%s", RS $0 ); next } # print XML specification junk
# Handle open-tags
match($0, /^[^\/ \r\n\t>]+/) {
TAG=substr(toupper($0), RSTART, RLENGTH);
TAGS=TAG "%" TAGS;
}
# Handle close-tags
/^[\/]/ {
sub(/^\//, "", $1);
sub("^.*" toupper($1) "%", "", TAGS);
$1="/"$1
}
{ printf("<%s", $0); } # Print everything
# Add extra stuff to HEAD section
TAGS ~ /^HEAD%/ {
P=""
printf("\n");
while((getline < headerfile) > 0)
{
printf("%s%s", P, $0);
P=RS;
}
printf("\n");
}
$