I am using Pycharm and trying to print text to the console
print('>')
>
print('>>')
>>
print('>>>')
The final print command ('>>>') prints a blank line. Why is that? How can I print out the three >'s?
If you can tolerate the space, you can do:
print(" >>>")
Related
Let's say I have a program (e.g. in Perl) that writes to STDOUT something like this:
print "123\t- 456";
print "\r+\n";
On my screen I see the following result:
123 + 456
However, when I redirect the output to a file >output.txt, such file will contain the following text:
123 - 456
+
How can I "reprocess" such text file into the result same as shown on the screen?
The col command will do this with the -b option to replace backspaces with the last character written to a column.
col -b < output.txt
I have a textfile that contains a story with many paragraphs and I want to print the story in the terminal, I also want to make it so when it finds a blank line in the textfile it adds another blank line to this in the whole story and print this as a new file.
I have this code but it only appends a new line when it finds a fullstop (so it adds a blank line to every sentence) and prints this as a new file:
awk -v RS="." '/^./ { print " " $0 " " }' < 52293-0.txt > output
What mistake am I making?
Many thanks,
This may be naive: how do I print a blank line from a gnuplot script to a txt file? I mean without any spaces, just a return.
set print "filename" append # I print things in a loop and append them
print a
print b
print HowToPrintBlankLines?
Thanks,
Luca
To print a blank line in gnuplot you can just do
print ""
I have an assignment asking me to print x iterations of a string for each character in that string. So if the string input is "Gum", then it should print out:
Gum
Gum
Gum
Right now my code is
my $string = <>;
my $length = length($string);
print ($string x $length, "\n");
And I'm getting gum printed five times as my output.
Those who have said you will get CR + LF at the end of the line on a Windows system are mistaken. Perl will convert the native line ending to a simple newline \n on any platform.
You must bear this in mind whether you are reading from the terminal or from a file.
The built-in chomp function will remove the line terminator character from the end of a string variable. If the string doesn't end with a line terminator then it will have no effect.
So when you type GumEnter you are setting $string to "Gum\n", and length will show that it has four characters.
You are seeing it five times on your screen because the first line is what you typed in yourself. The following four are printed by the program.
After a chomp, $string is just "Gum" with a length of three characters, which is what you want.
To output this on separate lines you have to print a newline after each line, so you can write
my $string = <>;
chomp $string;
my $length = length $string;
print ("$string\n" x $length);
or perhaps
print $string, "\n" for 1 .. $length;
I hope that helps
As you are simply using the input string, it still contains the newline at the end. This is also counted as a character. On my system, it outputs 4 Gum\n.
chomp($string) will remove the line ending, but the output will then also run together, resulting in GumGumGum\n
When You insert input and press enter afterwards You don't enter "Gum" but "Gum\r\n" which is a string of length 5. You should do trimming.
Your code is working fine. See this: http://ideone.com/AsPFh3
Possibility 1: It might be that you're putting 2 spaces while giving input from command line, that's why the length comes out to be 5, and it prints 5 times. Something like this: http://ideone.com/fsvnrd
In above case the my $string=<>; will give you my $string = "gum "; so length will be 5.
Possibility 2:
Another possibility is that if you use Windows then it will add carriage return (\r) and new line (due to enter \n) at the end of string. So it makes the length 5.
Edit: To print in new line: Use the below code.
#!/usr/bin/perl
# your code goes here
chomp(my $string=<>);
my $length = length($string);
print ("$string\n" x $length);
Demo
Edit 2: To remove \r\n use the below:
$string=~ s/\r|\n//g; Read more here.
I have the following simple line to print a new line to a log file:
Print #fileNumber, vbNewLine
However, this results in 2 newlines instead of one. My code does not have any other vbNewLines or anything that would print newlines.
If I do not have this print line, then I print no newlines, so this means this line is printing 2 newlines.
Does anyone have any ideas why?
Just tested this, and Print always adds a linebreak.
So simply using Print #fileNumber, will result in 1 blank line.
The problem is that Print already prints on a new line, so when you add vbnewline you're getting 2 lines.