<p>I need to do the following for hundreds of files:
Append the name of the file (which may contain spaces) to the end of each line in the file.</p>

<p>It seems to me there should be some way to do this:</p>

<pre><code>sed -e 's/$/FILENAME/' *
</code></pre>

<p>where <code>FILENAME</code> represents the name of the current file.  Is there a sed variable representing the current filename?  Or does anyone have a different solution using bash, awk, etc.?</p>

You could do it with a bash script
```
```
for i in * 
do
  sed -e "s/\$/$i/" "$i" 
done
```
```
One-liner version:
```
```
for i in * ; do sed -e "s/\$/$i/" "$i" ; done
```
```
Edit:
If you want to
replace
the contents of the file with the new, name-appended lines, do this:
```
```
TFILE=`mktemp`
for i in * 
do
  sed -e "s/\$/$i/" "$i" > $TFILE
  cp -f $TFILE "$i"
done
rm -f $TFILE
```
```