A file named start.txt exists. I am using a perl command which gives modified output using the content of start.txt and i am trying to overwrite the modified output to the same file
cat start.txt | perl -ne 'print "$1-$1.mp4 Lecture $2 -\n" while /.*\/videos\/(.*?mp4).*?(?<= )(\d+)/g;'> start.txt
Running the above command makes the file start.txt empty for some reason
There's no issue with my command because if i create a new file for redirecting the output like..
cat start.txt | perl -ne 'print "$1-$1.mp4 Lecture $2 -\n" while /.*\/videos\/(.*?mp4).*?(?<= )(\d+)/g;'> test.txt
This perfectly saves the expected output in test.txt but I don't want to create extra files , i need to overwrite the exiting file itself.
I tried >|
after reading its used to force overwrite files but still same issue.
I even tried | tee start.txt
, still causes the file to become empty .
On a side note : There are some awk commands which i use , if i try to save/redirect the output in a file from which the awk function reads text from , it causes the same issue of making the output file empty I would paste the awk command too if someone asks although i think there would be a universal solution for this