You're missing the point. The two files you haven't removed with your script are named 123.txt (original file) and 456.txt (original file) . Those names end with the string file) not with the string .txt .
Adding comments to what appears to be output from the command ls -1 (that is a digit 1, not the letter lowercase el) and adding comments only confuses those of us trying to help you.
Please show us the output you get from the commands:
0000000 061 062 063 137 146 151 156 141 154 056 164 170 164 012 061 062
1 2 3 _ f i n a l . t x t \n 1 2
0000020 063 137 151 156 144 145 170 056 164 170 164 012 061 062 063 137
3 _ i n d e x . t x t \n 1 2 3 _
0000040 162 145 155 157 166 145 056 164 170 164 012 061 062 063 056 164
r e m o v e . t x t \n 1 2 3 . t
0000060 170 164 012 064 065 066 137 146 151 156 141 154 056 164 170 164
x t \n 4 5 6 _ f i n a l . t x t
0000100 012 064 065 066 137 151 156 144 145 170 056 164 170 164 012 064
\n 4 5 6 _ i n d e x . t x t \n 4
0000120 065 066 137 162 145 155 157 166 145 056 164 170 164 012 064 065
5 6 _ r e m o v e . t x t \n 4 5
0000140 066 056 164 170 164 012
---------- Post updated at 08:15 AM ---------- Previous update was at 08:13 AM ----------
I will give the
find . -type f -iname \*.txt ! -iname \*_final.txt -delete
@RudiC there was no error as the bash did execute just didn't remove all the desired files, but I will try out the posted command. You are probably right in that there is less complicated/more optimal approach to this, but as I am a scientist I still have much too learn about shell scripting and being more efficient, but I am learning. Thank you :).
will delete ALL .txt files INCLUDING the original ones, UNLESS e.g. permissions get into the way, which in turn would result in error messages. BTW, the find ... for "_remove" and "_index" are unnecessary when above is run first.
awk -F'\t' -v OFS='\t' '
/^#/ {next
}
FNR == 1 {Q = NF
if (FN) close (FN)
print "echo rm " FILENAME
FN = FILENAME
sub (/\./, "_final.", FN)
}
{for (i=1; i<=Q; i++) if (!$i) $i="."
print FNR==1?"R_Index":FNR-1, $0 > FN
}
' OFS="\t" /home/cmccabe/Desktop/microarray/*.txt | sh
in lieu of your original bash script in post#1. Unfortunately, I can't test it, but it should create the desired output files (..._final...) with the desired index in front of every single line, and delete the original files (if the "echo" is removed).