I'm having problems writing records to an output file. When I do it in Textpad running on Windows, the output file looks fine. When, however, I copy the script to a Linux machine and use the exact same code, it appends a ^M character on each line written to the file. I have no idea why this is happening. I'm writing to the file by redirecting STDOUT to it.
open STDOUT,"> ${output}" || die "$0 can't open $ifile";
This is how I'm printing:
print $_;
I'm new to this, so if there's a better way to do it I'm all ears!
Thanks for the help!
4 2239 numberwhun 3,509
Recognized Expert Moderator Specialist
I'm having problems writing records to an output file. When I do it in Textpad running on Windows, the output file looks fine. When, however, I copy the script to a Linux machine and use the exact same code, it appends a ^M character on each line written to the file. I have no idea why this is happening. I'm writing to the file by redirecting STDOUT to it.
open STDOUT,"> ${output}" || die "$0 can't open $ifile";
This is how I'm printing:
print $_;
I'm new to this, so if there's a better way to do it I'm all ears!
Thanks for the help!
Well, the reason is, you copied from a Windows machine to a Unix based machine. The newline in Windows is a carriage return/line feed, but in Unix it is only a single line feed, no carriage return. Thus, when you view a file on Unix that has been on a Windows system, you will see a ^M at the end of every line. To avoid this, simply do this:
before the print statement. That will remove the ^M from the end of the line. You should also use chomp on variables after accepting input from the user. The reason? What is the last thing the user does to submit their answer? Hit enter, causing a carriage return/line feed to be entered into the variable.
Regards,
Jeff
Hi.. if you just want to remove the ^M characters from the output file, you can use the command - dos2unix filename filename
.
this command will remove the ^M s.... actually this command changes the file from the dos format to unix format..
filename can be the same name or different name.. giving same name over writes the existing file..
I dont know if this is any help as this is not related to scripting.. once you get the output file you can use this command to remove ^M..
numberwhun 3,509
Recognized Expert Moderator Specialist
Hi.. if you just want to remove the ^M characters from the output file, you can use the command - dos2unix filename filename
.
this command will remove the ^M s.... actually this command changes the file from the dos format to unix format..
filename can be the same name or different name.. giving same name over writes the existing file..
I dont know if this is any help as this is not related to scripting.. once you get the output file you can use this command to remove ^M..
You are correct that dos2unix does achieve this, but the OP would not have to issue an extra system command if they simply used the chomp() command in their code which does the same thing as dos2unix, but on each line before it is written to the file.
Regards,
Jeff
Ya Jeff.. you r correct :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Paul Watson |
last post by:
How can I write lines to stdout on a Windows machine without having '\n'
expanded to '\r\n'.
I need to do this on Python 2.1 and 2.3+.
I see the msvcrt.setmode function. Is this my only path? Is it valid to
change the mode of stdout? The file.newlines is not writable.
|
by: Mike |
last post by:
I would like my 'print' statements to send its output to the user's
screen and a log file.
This is my initial attempt:
class StdoutLog(file):
def __init__(self, stdout, name='/tmp/stdout.log',
mode='w',bufsize=-1):
super(StdoutLog, self).__init__(name,mode,bufsize)
self.stdout = stdout
|
by: Nainto |
last post by:
Hello, I have posted before about trying to find the status of an FTP
uplaod but couldn't get anything to work. After some more searching I
found
http://groups.google.com/group/comp.lang.python/browse_thread/thread/76be9a994547db4/91917c906cdc04d4?q=ftp+progress&rnum=1#91917c906cdc04d4
but it does not seem to work because it just uploads the file and does
not print a . onto the screen. HEre is the code I have when I'm using
the code from...
|
by: hpy_awad |
last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using
fgets but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
/* Book name :
File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp
Program discription: Adding name,Address to customer_record SETUP
PROGRAM
|
by: kimimaro |
last post by:
hi below is my save function that is used to placed data from the C program
to a text file for future usage.
void save()
{
FILE *save;
int i = 0;
save=fopen("employeerecord.txt", "a+");
| |
by: goodnamesalltaken |
last post by:
Hello fellow python users,
I've been working on a basic implementation of a privilege separated
web server, and I've goto the point of running a basic cgi script.
Basically when the execCGI function in my Unpriv.py program is called a
few things should happen, it should fork (which it does), the stdout of
the child should be redirected to a given pipe (which it does), and the
script should execute using execve(which is has problems...
|
by: allpervasive |
last post by:
hi all, this is reddy, a beginner to c lang,,here i have some problems
in reading and modifying the contents of a file,, hope you can help to
solve this problem. Here i attach the file to be modified and the
program code.
In the attached file below i just want to change the value of
data(only float value) after the line 1 P V T 1 15 till 2 G TT,
from positive to negative and vice versa, and wire the date in other
file. can someone help...
|
by: hemant.gaur |
last post by:
I have an application which writes huge number of bytes into the
binary files which is just some marshalled data.
int len = Data.size(); //arrary size
for (int i = 0; i < len; ++i)
fwrite(&Data, 1, 1, f);
now after running this for long time and pushing millions of bytes, It
once misses writing the last byte of fData. Then the further push of
bytes is again correct. As i am not using the return value for the
|
by: pcfreak30 |
last post by:
ok, i probably have not been registered here long, but i am no noob. I am very experienced in php, but the php cli is a bit of new territory for me.
I am trying to create a simple little script that will fetch a webpage and save it to a file. This is just for practice for the records.
here is my code:
<?php
fwrite(STDOUT,"Created By Derrick Hammer\n");
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |