Knowledge map advanced must read: read how large-scale map data efficient storage and retrieval>>>
When using Perl script in * Nix system, we sometimes encounter the following errors:
/usr/bin/perl^M:badinterpreter:Nosuchfileordirectory
The most common reason is that the script is edited in Windows system. The newline character in Windows system is “R” while it is only “n” in UNIX system. If you want to solve this problem, just remove the
The first solution is to use sed (assuming that the script in question is named file name)
sed-i's/\r$//'filename
This solution is suitable for simple ASCII file format. If the situation is more complicated, for example, if the file name is a Unicode file, some new line breaks in Unicode may be introduced; In addition, sometimes the character codes of the two systems are not consistent. The vertical tab character 0x0b and the paper feed character 0x0c are even more troublesome. Fortunately, Perl provides another solution:
perl-p-i-e"s/\R/\n/g"filename
Here, we use the character group “R” introduced from Perl 5.10 to match various newline characters. We just need to replace it with “n”. At the same time, there is no need to use a script file to implement, just execute such a command in the shell. Where – P means to operate on the file name line by line, – I means to operate in place, to cover the original file, – e means to execute the following statements
Similar Posts:
- [Solved] Expected linebreaks to be ‘LF’ but found ‘CRLF’.
- When Linux runs SHELL file, $’\ R’: command not found appears
- [Solved] SyntaxError: unexpected character after line continuation character
- Shell script error newline syntax error near unexpected token
- Conversion to MySQL shell script execution error $’\ R’: command not found
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-1:
- [How to Solve Error] warning: LF will be replaced by CRLF in README.md.
- Can’tlocate cpan.pm in@inc [How to Solve]
- [Solved] error: ‘gets’ was not declared in this scope; did you mean ‘fgets’?
- The difference between UTF-8 and utf-8-sig