In a bash script, I try to call the following Perl command on each file, and then I want to redirect the Perl command's output to that file.
The Perl command simply removes the comments from the file. When it prints to the console it seems to work. But when I try to redirect the output to each individual file, the file becomes empty. What am I doing wrong here?
#!/usr/bin/env bash
shopt -s globstar
for file in ./**/*.java; do
perl -0pe 's|//.*?\n|\n|g; s#/\*(.|\n)*?\*/##g; s/\n\n+/\n\n/g' "$file" > "$file";
done