Hi,
I would like to insert a file's filename into the first line of that file - for a batch of files. Is this possible using SED? Thanks in advance.
for file in `ls -1 *`
do
echo "$file" > ./tmpfile
cat "$file" >> ./tmpfile
mv ./tmpfile "$file"
done
is one way to do this.
How about this:
for i in *; do
ex $i <<EOF
i
$i
.
wq
EOF
done
I doubt that it would be very easy to do it using sed, as sed writes to standard output. You would have to pull stunts like redirecting standard output to a file at the beginning of the script and changing that for every file that you want to change...