I am attempting to run a shell script that loops through all files in a directory that I specify when executing the shell script, removes all commas in the file, and saves it as the same filename.
The problem is that it's deleting everything in each file, and I'm unsure why, but believe it has to do with "$filename";
. I've tried putting it in brackets too, but I'm new to Bash.
I run it like so:
NaN$ ./remove_commas.sh /path/to/dir
./remove_commas.sh
#!/bin/bash
dir="$@"
for filename in $dir/*; do
echo "$filename"
cat "$filename" | tr -d ',' > "$filename";
done