Save result to a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Save result to a text file
# 1  
Old 01-29-2013
Save result to a text file

Currently I have a perl code to combine two different files.
Code:
#! /usr/bin/perl -w

use strict;

open FP1,"A.txt";
open FP2,"B.txt";
my ($l1,$l2);
while(1)
{
  $l1=<FP1>; chomp $l1;
  $l2=<FP2>; chomp $l2; 
  last unless(defined $l1 or defined $l2);
  print "$l1 $l2\n";
}

close FP2;
close FP1;

May I know how to save the result directly to A_B.txt?
So, I can only run
Code:
./paste

without need to
Code:
./paste > A_B.txt

# 2  
Old 01-29-2013
Well that would be the general way to do it.

you can always add it into your perl script.

just add `./paste > A_B.txt`; to your code at the end.
This User Gave Thanks to Grant Pryor For This Post:
# 3  
Old 01-29-2013
Code:
 
#! /usr/bin/perl -w
use strict;
open FP1,"A.txt";
open FP2,"B.txt";
open FP3, ">A_B.txt" or die $!;
my ($l1,$l2);
while(1)
{
  $l1=<FP1>; chomp $l1;
  $l2=<FP2>; chomp $l2; 
  last unless(defined $l1 or defined $l2);
  print FP3 "$l1 $l2\n";
}
close FP3;
close FP2;
close FP1;

These 2 Users Gave Thanks to itkamaraj For This Post:
# 4  
Old 01-29-2013
Simple command in UNIX :- This command might be useful to you

Code:
 
paste file1 file2 > a_b.txt


Best Regards
Kalyan
# 5  
Old 01-29-2013
thanks for the post itkamaraj
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use text of one file to save in another

I am trying to use the text of one file as a text file name with and the text of another as the contents of that text file. Is this possible? Thank you :). For example, in the two files attached, target.txt has: 1.txt 2.txt and out_parse.txt has: 13 20763642 20763642 C G... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Dummies Questions & Answers

I save the result in a variable

I have friends that this command worked perfectly, but I would like to save the result in a variable, which I have not achieved var=prueba.txt echo $var | cut -d "." -f 1 prueba I need to do this but does not work me salida=echo $var | cut -d "." -f 1 echo "result:$salida" ... (8 Replies)
Discussion started by: tricampeon81
8 Replies

3. Shell Programming and Scripting

How to save the 'nmon' output to a text file with a script?

Hi all, I want to do an Unix Script to save the 'nmon' output on a text file and I don't know how to do it. I need a Script for each monitoring and also one to multiple monitorings. Thanks (6 Replies)
Discussion started by: Javi1990
6 Replies

4. Shell Programming and Scripting

Open Text file input data and save it.

Hi Guys, I have blank file A.txt I will run the script xyz.sh First i want to open a.txt file... Now i will enter some data like XYZ ABC PQR .. Save it and keep continue my script.... END of my script. Thanks (1 Reply)
Discussion started by: asavaliya
1 Replies

5. Shell Programming and Scripting

awk and save result on a different file

Hi, If I type: ls -l *txt | awk '{print $8}' I get the file listing if I am in the directory. If I try to do the same from a job flow, doing also other things, I can't do ls -l directory/*txt | awk '{print $8}' > directory/result.txt or echo ls -l directory/*txt | awk '{print... (8 Replies)
Discussion started by: essemario
8 Replies

6. Shell Programming and Scripting

Way to save output result of a program into another new file...

Does anybody know any alternative way to save output result of a program into another new file? I got try the command below: program_used input_file > new_output_file program_used input_file >> new_output_file Unfortunately, both the ">" and ">>" is not work at this case to save the output... (6 Replies)
Discussion started by: patrick87
6 Replies

7. Shell Programming and Scripting

"Time" command and save result in a file.txt

Hi, I'am using "time" to check execution time of some script. Is there any possibility to save time command result into a file ? (2 Replies)
Discussion started by: Physix
2 Replies

8. Shell Programming and Scripting

Data fetched from text file and save in a csv file

Hi i have wriiten a script which fetches the data from text file, and saves in the output in a text file itself, but i want that the output should save in different columns. I have the output like: For Channel:response_time__24.txt 1547 data points 0.339 0.299 0.448 0.581 7.380 ... (1 Reply)
Discussion started by: rohitkalia
1 Replies

9. Shell Programming and Scripting

save the HTML result

Hi all, I am displaying my result in HTML format using tables. I want to save the results in file in the same format along with the table only. How do i do that in perl? I have attached the table structure . I want to save like that itself . with regards (2 Replies)
Discussion started by: vanitham
2 Replies

10. Shell Programming and Scripting

can I save list of files in memory and not in text file?

Hello all im using allot with the method of getting file list from misc place in unix and copy them into text file and then doing misc action on this list of files using foreach f (`cat file_list.txt`) do something with $f end can I replace this file_list.txt with some place in memory? ... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question