Assume a multi-line text file (file1) that contains filepaths.
$ cat file1
./foo/foo
./foo/bar
./foo/baz
I would like to save only the filenames to file2 and prepend each filename with some special characters (e.g., [#).
I know that I can do this via a simple for-loop, but I understand this is considered an unfavorable practice.
for line in $(cat file1); do
echo "[#" $(basename "$line") >> file2;
done
I believe this task can be done cleaner via awk, but the below code is only a fragment. How do I perform the above task with awk?
awk '{print "[#",$0=$(basename $0)}' $file1 > $file2