Assume a multi-line text file (file1) that contains filepaths.$ cat file1./foo/foo./foo/bar./foo/bazI 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); doecho [# $(basename $line) >> file2;doneI 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
Conducting multi-line string operation with awk instead of for-loop
awk;string
Use / as the field separator, and print the last field:$ awk -F/ '{print [#$NF}' file1[#foo[#bar[#baz