I'm guessing the first b.txt is a typo then, since the file is a.txt?
A slight change to that awk script might work, then:
#!/bin/sh
# Usage: SCRIPT file1 file2 ...
# If you don't have tempfile, try mktemp.
# if you don't have mktemp, try TEMP=/tmp/$$.
TEMP=`tempfile`
for f; do
awk '{print $0, FILENAME}' "$f" >$TEMP
# cat is better than mv because it won't alter the original's
# ownership or access flags.
cat $TEMP > "$f"
done
rm -f $TEMP
Neat use of 'for', yazu, didn't know it could take input from $1...$N like that.
What input dir? It doesn't have an input dir. The comments tell you how to use it:
# Usage: SCRIPT file1 file2 ...
so you could run my unmodified script as ./myscript /temp/files/*
Or you could modify the script as
# If you don't have tempfile, try mktemp.
# if you don't have mktemp, try TEMP=/tmp/$$.
TEMP=`tempfile`
for f in /path/to/input/* ; do
awk '{print $0, FILENAME}' "$f" >$TEMP
# cat is better than mv because it won't alter the original's
# ownership or access flags.
cat $TEMP > "$f"
done
rm -f $TEMP