What is the meaning of 'trailing newline is stripped'?

  • Thread starter Thread starter hilman
  • Start date Start date
  • Tags Tags
    English
Click For Summary
SUMMARY

The term 'trailing newline is stripped' refers to the process of removing newline characters from text files to ensure compatibility across different operating systems, particularly between Windows and Unix-based systems. In Windows, text lines are typically terminated with both a carriage return and a line feed, while Unix systems use only a newline character. This discrepancy can lead to issues when files are transferred between systems, necessitating the removal of these characters for proper file reading. The discussion highlights the importance of understanding newline handling in programming languages such as Python and C++.

PREREQUISITES
  • Understanding of newline characters and their role in text files
  • Familiarity with operating systems, specifically Windows and Unix
  • Basic knowledge of programming languages like Python and C++
  • Awareness of file transfer protocols and their impact on text formatting
NEXT STEPS
  • Research how to handle newline characters in Python using the 'strip()' method
  • Learn about text file handling in C++ and the differences between 'getline' and '>>' operations
  • Explore JSON formatting rules regarding newline characters
  • Investigate tools for converting text files between Windows and Unix formats
USEFUL FOR

Programmers, software developers, and system administrators who work with cross-platform text file compatibility and need to manage newline character issues effectively.

hilman
Messages
17
Reaction score
0
This is a term I found in a programming tutorial. Since English is not my first language, and this term is also kind of a computer term, I am not so clear with the meaning. Can someone explain it to me?

Thanks.
 
Technology news on Phys.org
Newline characters indicate that the file has reached the end of the line and that any program should read the next line. The newline character can differ between systems so it is sometimes necessary to remove them. For example, a newline character created in Notepad on Windows will show up as odd text when viewing it on a Unix-based system. Therefore, it is necessary to strip them in order for the file to be read correctly.
 
  • Like
Likes hilman
To expand slightly on what Borg said, one of the things that is a result of this fact is that if you have an HTML file on a windows system, each line will be terminated by both a carriage return and a line feed. If you then upload that file to a Unix based server and look at the file size, you will see that it is smaller by a number of bytes corresponding to the number of lines, because all the line feeds have been removed.
 
  • Like
Likes jim mcnamara
hilman said:
This is a term I found in a programming tutorial.

For which programming language? Which operation or function was the tutorial discussing? If you tell us the context in which that term was used, we can be more specific in our response.
 
I think Phinds nailed it - carriage control in text files is dependent on the operating system's native carriage control for text files. For modern applications and languages. and Linux/Windows

I think jtbell is thinking about stuff like FORTRAN and IBM COBOL carriage control words (bytes) that live at the start of a line of text and are ancient holdovers from data entry via punch cards or paper tape. I know because I'm ancient... and lived through that nightmare.
 
Actually, I was thinking of C++ and the 'getline' versus '>>' stream input operations.

Now that we've guessed three different possible contexts, hopefully the OP will tell us which one it is, or if it's something else!
 
  • Like
Likes jim mcnamara
jtbell said:
For which programming language? Which operation or function was the tutorial discussing? If you tell us the context in which that term was used, we can be more specific in our response.
I'm sorry because I forgot. I think it was python because I was just doing some fast reading. Anyway, I think I do got the point. Thanks.
 
phinds said:
because all the line feeds have been removed.

Between Unix and Windows the carriage return is added/removed, not the newline. In Unix, text lines are terminated with newline only (\n).

It's impossible to answer the OP with any specificity since we don't know the context. For example, json has rules about newlines.
Or, maybe the tutorial was an example about how one could strip newlines.
 
  • Like
Likes phinds
meBigGuy said:
Between Unix and Windows the carriage return is added/removed, not the newline. In Unix, text lines are terminated with newline only (\n).
OOPS. Thanks.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
5K
Replies
69
Views
10K
  • · Replies 16 ·
Replies
16
Views
3K
Replies
16
Views
3K
Replies
37
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 112 ·
4
Replies
112
Views
9K
  • · Replies 43 ·
2
Replies
43
Views
6K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 11 ·
Replies
11
Views
2K