I have various files which contain only one column and I would like to add a second column which contain as rows the names of the prefix of the files:
Example:
file1_phone.txt looks like:
A
B
C
file2_phone.txt looks like
D
E
F
Output:
file1_phone.txt
A file1
B file1
C file1
file2_phone.txt
D file2
E file2
F file2
I wrote this loop in linux:
for f in *.txt; do
b="${f%%_phone.txt}"
awk -v RS='\r\n' 'BEGIN { OFS = " " } {print $0, "$b"}' "${f}" > "${f}".new
done
However, it seems it will give this output:
Output:
file1_phone.txt looks like
A $b
B $b
C $b
file2_phone.txt looks like
D $b
E $b
F $b