I have a loop and I want to select some columns with awk and do sort, and then rename my output file with a new name. My awk and sort are working well, but I want to get a file name with a different name of my input file and I was not able to do it. I have different directories to run this loop: a, b and c. The command is:
for i in a b c
do
(cd $i/; for i in *_test2.txt; do awk '{print $2"_"$1}' $i | sort -V > ${i%.txt}3.txt; done)
done
I would like to change the name of the file to *_test3.txt
, but in my loop I will have the output as *_test23.txt
How can I do that?
awk
andsort
?