Why my files ended with ^M ?? (shell/bash)
I have a file.sh with the next commands:
#!/bin/bash
sed 1q file.txt > file_0.txt
grep -w "name" file.txt > file_1.txt
cat file_0.txt file_1.txt > final_file.txt
When I run: sh file.sh I obtain this error:
cat: file_0.txt: No such file or directory
cat: file_1.txt: No such file or directory
In the last command (cat) the files are not recognized because the final names are:
file_0.txt^M
file_1.txt^M
Why outputs end with ^M ? How can I solve that?
• 1,758 views
•
link
2 answers
Finally I solved that with the next command:
sed -i 's/\r$//' file.sh
• 0 views
•
link
Log in to answer this question.
Somewhere during their journey, the files visited windows.