Hi all,
I am new to perl and I have written a smal script to grab data from one file, and put them into another file. The problem is new lines, which are printing nice under a linux environment, but it is all messed up if I open it with notepad. I am running Perl 5 under cygwin. Heres the script: -
#!/usr/bin/perl
-
-
open (READ, "opt.txt") || die "Can't find opt.txt\n";
-
-
$x=0;
-
-
while ($info = <READ>) {
-
chomp $info;
-
@data = split (/\t/, $info);
-
push @cells, [@data];
-
$x++;
-
}
-
-
close READ || die "Couldn't close opt.txt";
-
open (WRITE, ">rel.txt") || die "Can't find rel.txt\n";
-
-
$y=0;
-
-
print WRITE "#DoNotEditThisLine: UndoCommandFile off_files model_n_m_z endfile=/tmp/6222\n\n";
-
-
foreach (@cells){
-
print WRITE "cr balla=1,blablabla=$cells[$y][0],foobar=$cells[$y][0]_$cells[$y][1]\n";
-
print WRITE "bleh=10175,foounbar=$cells[$y][1]\n\n";
-
-
-
$y++;
-
}
-
-
close WRITE || die "Couldn't close rel.txt";
-
exit (0);
-
Now if I cat the output in cygwin, the newlines are working. If I open it with notepad, one new line is working which is after print WRITE "bleh=10175,foounbar=$cells[$y][1]\n\n"; (please note not both of newlines are working).
Any ideas? I need those in that specific format
1 5891
Your problem is that different operating systems (OS) use different characters to make a line break. Therefore "\n" will be converted to one or 2 characters, depending on the OS where the program runs.
UNIX-like Linux, FreeBSD und Solaris use a single LineFeed (LF, ASCII-Code 10).
Mac OS up to Version 9 uses a sinle Carriage Return (CR, ASCII-Code 13).
MS-DOS and Windows use 2 characters to delimit a line: a CR followed by a LF.
The problem is that you have created the text under Unix-environment, therefore you have a single LF. But Notepad runs under Windows and expects CR-LF. Notepad doesn't have the feature to autodetect the correct format, but other editors do: UltraEdit, WinVi, jEdit, ... and, if you still want to stay with Microsoft: Wordpad!
That means: just use Wordpad instead of Notepad.
Or convert the lf to cr-lf in your text by using Cygwin command unix2dos, before opening your file in Notepad
Sign in to post your reply or Sign up for a free account.
Similar topics
by: xegfault |
last post by:
Here is a simple script:
#!/usr/bin/python
print "No newline, please.",
# End of script
When the program runs, python is still printing a newline when the
program exits. How does one keep...
|
by: JC |
last post by:
I am using Mysql version: 4.0.18-max-log
and trying to populate a database from a text file using source option from
inside the mysql environment.
The population run OK but when creating the...
|
by: Romain |
last post by:
Hello,
I am writing out a binary file. I figured that the number "10" is
automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are
line feed and carriage return.
I know it does...
|
by: Daniel |
last post by:
when writing out a file from .net, when is the file created? after the bytes
are all written to the hard drive or before the bytes are written to the
hard drive?
|
by: Ross Reyes |
last post by:
HI -
Sorry for maybe a too simple a question but I googled and also checked my
reference O'Reilly Learning Python
book and I did not find a satisfactory answer.
When I use readlines, what...
|
by: Fred Dag |
last post by:
Hi,
When writing using both these methods ( StreamWriter.Write("\n") vs
WriteLine() ) to a file and open in Notepad I see a special character
instead of newlines with Write("\n") vs a newline...
|
by: tubby |
last post by:
Silly question, but here goes... what's a good way to determine when a
file is an Open Office document? I could look at the file extension, but
it seems there would be a better way. VI shows this...
|
by: Jack |
last post by:
Hi there MYSQL is loading a non printable character at the end of each
row, clearly its a newline or ENTER character.. I have tried
dos2unix.exe, a perl program that converts dos files to unix,...
|
by: Jim |
last post by:
Hi There,
I'm trying to read a file character by character. When I write the
file out, there is one extra character which shows on the screen as a
solid circle with a small question mark in the...
|
by: =?Utf-8?B?S3VtYXI=?= |
last post by:
I am using granados telnet client for connecting to the telnet and get the
data from it. Every thing appears to be going smooth. But for some reason
when I try to write the byte data to a string or...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |