guides:software:files
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
guides:software:files [2021/01/04 15:05] – wikiadmin | guides:software:files [2024/07/25 15:01] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
There is a difference in how files are stored on these two operating systems. | There is a difference in how files are stored on these two operating systems. | ||
- | By default, when files are created on a windows system, the end of the file is marked with a **ctrl-r** and a **ctrl-n**. The user does not insert this, it is done automatically by the software. | + | By default, when files are created on a windows system, the end of each line is marked with a carriage return (\r) |
- | ===== Checking for **CTRL-R** | + | In addition, most files in linux contain a final new line marker. |
- | To see if your file contains | + | |
+ | These differences can cause problems when processing files. | ||
+ | |||
+ | ===== Checking for Carriage Return | ||
+ | To see if your file contains | ||
+ | |||
+ | In this example, the file foo.cpp has been created on a computer running windows and transferred to a computer running linux. | ||
+ | |||
+ | < | ||
+ | $ more foo.cpp | ||
+ | #include < | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main() { | ||
+ | cout << "Hello World " << endl; | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | $ od -c foo.cpp | ||
+ | 0000000 | ||
+ | 0000020 | ||
+ | 0000040 | ||
+ | 0000060 | ||
+ | 0000100 | ||
+ | 0000120 | ||
+ | 0000140 | ||
+ | 0000160 | ||
+ | 0000164 | ||
+ | |||
+ | </ | ||
+ | |||
+ | In the following example, the file '' | ||
+ | < | ||
+ | $ more bar.cpp | ||
+ | #include < | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main() { | ||
+ | cout << "Hello World " << endl; | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | $ od -c bar.cpp | ||
+ | 0000000 | ||
+ | 0000020 | ||
+ | 0000040 | ||
+ | 0000060 | ||
+ | 0000100 | ||
+ | 0000120 | ||
+ | 0000140 | ||
+ | 0000153 | ||
+ | |||
+ | </ | ||
+ | Note in this example that lines end with a newline (\n) but not a carriage return (\r). | ||
+ | |||
+ | ===== Converting Files Between Systems ===== | ||
+ | |||
+ | The utility programs **dos2unix** and **unix2dos** are provided to convert files between the two different operating systems. The first will remove the carriage return from the and of each line, and the second will add one. | ||
+ | |||
+ | In this example, the user wishes to convert the file '' | ||
+ | |||
+ | < | ||
+ | $ dos2unix foo.cpp | ||
+ | </ | ||
guides/software/files.1609772706.txt.gz · Last modified: 2024/07/25 15:01 (external edit)