Perl - How to print a "carriage return" to an output file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl - How to print a "carriage return" to an output file?
# 1  
Old 03-05-2009
Perl - How to print a "carriage return" to an output file?

Let's say I want to write a program that run these 4 UNIX commands and redirect output to a file.

#!/usr/local/bin/perl
use strict;

`cd \$HOME > output.txt`;
`cut -f1 inputfile.txt >> output.txt`;
`hostname >> output.txt`;
`ifconfig >> output.txt`;

I want to print a "carriage return" or "---------" after each command to separate them and pretty up the output.txt. How would I do that?
# 2  
Old 03-05-2009
you can use echo -e to handle that.

After each >> output.txt you want to put a separator in just add the line

echo -e "--------------\n"
# 3  
Old 03-05-2009
how about:
Code:
#!/usr/local/bin/perl
use strict;

`cd \$HOME > output.txt`;
`echo --------------- >> output.txt`;
`cut -f1 inputfile.txt >> output.txt`;
`echo --------------- >> output.txt`;
`hostname >> output.txt`;
`echo --------------- >> output.txt`;
`ifconfig >> output.txt`;

# 4  
Old 03-05-2009
Quote:
Originally Posted by Yogesh Sawant
how about:
Code:
#!/usr/local/bin/perl
use strict;

`cd \$HOME > output.txt`;
`echo --------------- >> output.txt`;
`cut -f1 inputfile.txt >> output.txt`;
`echo --------------- >> output.txt`;
`hostname >> output.txt`;
`echo --------------- >> output.txt`;
`ifconfig >> output.txt`;

Thanks. Just like I wanted.

I modified it a bit to add spaces before and after the ----.

Quote:
`echo "\n -----------------------------------------\n" >> output.txt`;
# 5  
Old 03-06-2009
Odd.... there is no perl code in your perl script.
# 6  
Old 03-06-2009
Quote:
Originally Posted by KevinADC
Odd.... there is no perl code in your perl script.
right. teiji, why don't you consider using a shell script instead of perl script? something like:
Code:
#! /bin/bash
cd $HOME > output.txt
echo --------------- >> output.txt
cut -f1 inputfile.txt >> output.txt
echo --------------- >> output.txt
hostname >> output.txt
echo --------------- >> output.txt
ifconfig >> output.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

PERL: DBI - Is it possible to get a "nicer" formatted return?

Hi, I am currently writing a perl module that will be passed queries from other scripts and use DBI to execute them on an Oracle Database. The problem I have is when it comes to the return. I am currently getting this from my code: FIELDA FIELDB FIELDC ... (6 Replies)
Discussion started by: chris01010
6 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

perl -MConfig -e 'print "$Config{byteorder}\n";'

What exactly is this code returning: perl -MConfig -e 'print "$Config{byteorder}\n";' I am executing this command in two platforms. In AIX i am getting : 4321 In Linux i am getting: 12345678 Does it mean that a byte size in aix is of 4 bits(is it possible)? Also, will there be... (2 Replies)
Discussion started by: baig_1988
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

7. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

10. Shell Programming and Scripting

perl "system" cmd return values..

perl 5.6.1: when i try a "system" command(with if loops for $?), i get this: child exited with value 1 what is meant by this $? values and what does it meant if it returns 1?.. (0 Replies)
Discussion started by: sekar sundaram
0 Replies
Login or Register to Ask a Question