Hello. I am trying to write a simple script (one of my attempts is below) to multiply the contents of a file by -1. I have a folder filled with many files and these txt files are each a single column of numbers and I just need to flip the signal to negative numbers and save out the inverted version of each. I am unable to write a cygwin script to do it properly. Any assistance is appreciated.
for file in *txt
do
$file | bc -q
$file *-1 > $file-inverted.txt
done
echo "files inverted"
You can experiment a little with how you want your data inside double-quotes, but you need to make sure the unix environment does not attempt to interpret your text. Think that a -1 is very similar to an option in appearance. [For example, the command ls -1 would list files in one column.]
> echo "5" "*" "-1" | bc
-5
> echo "-55" "*" "-1" | bc
55
Thank you for the response. I have experimented with the quotes and it still isn't working properly. It seems to be having trouble with the use of $file in conjunction with bc.
I am fairly new to unix scripts, so forgive me if I'm missing something obvious.