I am trying to use awk to rename all .txt files in a directory based on a match to a column in a file. That is the string before the the .txt will be an exact match to $2 of file,
the text file is then renamed with the $1 value. he awk does execute, but not with the desired result. Thank you :).
current directory structure
123_1.txt
456_2.txt
789_3.txt
file
aaa 123_1
bbb 456_2
ccc 789_3
awk
ls *.txt | awk -vvar=$2 '{f=$1 ; sub($2,var); print "mv", f, $0 } ' file
current
mv aaa 123_1 aaa
mv bbb 456_2 bbb
mv ccc 789_3 ccc
desired directory
aaa.txt
bbb.txt
ccc.txt