rewrite the same info in 3 different files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rewrite the same info in 3 different files
# 1  
Old 03-28-2003
rewrite the same info in 3 different files

i would like to be able rewrite the same info in 3 different files

/path/file1.ext
/path/file2.ext
/path/file3.ext

can u help me please with shell script ?

lets say i want to write "12345"

thanks
strok
# 2  
Old 03-28-2003
I'm sure there's a lot of ways to do this...

command > file1.ext
cp file1.ext file2.ext
cp file1.ext file3.ext

You can also try using the tee command, but it may only work on the C shell.

To write to the files:
command | tee file1.ext file2.ext file3.ext

To append to them:
command | tee -a file1.ext file2.ext file3.ext
# 3  
Old 03-28-2003
If perl is anygood to you.

Quote:
#util to write info to three files
#version 1.0


#open files
open (FILE1, "> c:\\Documents and settings\\file1.txt") or die "Cant open file: $!";
$file1 = FILE1;
open (FILE2, "> c:\\Documents and settings\\file2.txt") or die "Cant open file2: $!";
$file2 = FILE2;
open (FILE3, "> c:\\Documents and settings\\file3.txt") or die "Cant open file3: $!";
$file3 = FILE3;

#put text into files
print $file1 "12345678910";
print $file2 "12345678910";
print $file3 "12345678910";

#close text files
close (FILE1);
close (FILE2);
close (FILE3);
# 4  
Old 03-28-2003
Yeah, that Perl script would work too. And if you want to append, use >> instead of > so that the data in the file doesn't get written over.

perleo, you really don't need $file1 = FILE1, $file2 = FILE2, etc.. you can just use the filehandles FILE1, FILE2 and FILE3 in the print command.
# 5  
Old 03-28-2003
This sounds vague enough to possibly be homework...

What do you have written so far? What shell? Why do you need it in 3 different files? How is the information stored (in a varible, a disk file, coming in from a pipe)?
# 6  
Old 03-29-2003
the perl one is good enough

thanks alot
strok
# 7  
Old 03-29-2003
Quote:
Originally posted by LivinFree
This sounds vague enough to possibly be homework...

What do you have written so far? What shell? Why do you need it in 3 different files? How is the information stored (in a varible, a disk file, coming in from a pipe)?
i just got 8 .htaccess files with my ip listed in to it
and now i have a new ip almost every month.....
strok
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two files and extract info

Hello, I have two files which look like this File 1 Name test1 status P Gene1 0.00236753 1 1.00E-01 Gene2 0.134187 2 2.00E-01 Gene3 0.000608716 2 3.00E-01 Gene4 0.0016234 1 4.00E-01 Gene5 0.000665868 2 5.00E-01and file 2 No Pos ... (2 Replies)
Discussion started by: nans
2 Replies

2. Red Hat

Info on /dev/dm files

Hi, I was looking at my /dev directory and found some files of the pattern dm?. I searched on google and found that it is a device manager file for LVM. But nothing but that. Can someone give me some info on when these files are created and if we can use this as instead of... (7 Replies)
Discussion started by: prithvirao17
7 Replies

3. Shell Programming and Scripting

psftp: get all files info in a choosen file

Dear all, We are trying to get file information in a file from our sftp server with the program psftp. lcd d:\sftpInfo cd serverInfo ls *.* > qqqqq.txt After running the ls command, we see all files who are in the serverInfo directory on the screen. No error is showed. Our question is:... (3 Replies)
Discussion started by: ton2204
3 Replies

4. Shell Programming and Scripting

matching and extracting info from text files

Hi all, I have two .txt file i.e. First text file: 2 4 1 4 Second text file 2 1.nii.gz 4 334.nii.gz 1 12.nii.gz 4 134.nii.gz If entry in 1st column of 1st text file matches the 1st column of 2nd text file, then copy the file (name of which is the second column) associated with... (4 Replies)
Discussion started by: vd24
4 Replies

5. Shell Programming and Scripting

Renaming files by matching info from a separate file

Hi All, I could use a bit of help with this as I'm at a loss. I have a number of files all named accordingly: I have a separate text file that is as follows: What I want to do is end up with: I don't know how to do this, though I'm certain it can be done, and would rather learn how... (14 Replies)
Discussion started by: Demosthenes
14 Replies

6. Shell Programming and Scripting

merging info from 2 files into 1

Hi, I have 2 files that I need to combine. I'm not sure if there is an easy way to use grep or something to combine them how i need. Basically I have 2 csv files. Each file shares an ID for a line of information, but has a bunch of other so I can't easily combine them. file1:... (2 Replies)
Discussion started by: kevin9
2 Replies

7. Shell Programming and Scripting

Find files older then today & display with timestamp info

Small query- I want to do some operation on all the files older then today. Before I do that operation, i want to verify if the command works properly or not. Surprisingly, the command below returns me file, which are created today - find /mrk_archive/PG/ftp/incomming/gbs/2008 -type f... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

8. AIX

need to extract info from log files

hi guys i need to extract information from log files generated by an application. log file has the following lines for each process.. ---------------------------------------------- Fri Aug 03 12:06:43 WST 2007 INFO: Running project PROJECT1 Fri Aug 03 12:06:43 WST 2007 INFO: Source Files... (7 Replies)
Discussion started by: kirantalla
7 Replies

9. Shell Programming and Scripting

How can I get multiple info from different files

HI, Supose I have these 2 files: file1.txt Name: John Age:28 DateOfBirth:21/12/2004 file2.txt Name: Thomas Age:30 DateOfBirth:11/1/2003 I need to retrieve into a single file the "Name" and "DateOfBirth" from the 2 files, so the result looks like this: file3.txt John:21/12/2004... (3 Replies)
Discussion started by: efernandes
3 Replies

10. UNIX for Advanced & Expert Users

How to find all the log files under the root directory -- Need Info

Hi I need to find all the log files under the root directory and delete them if necessary, if any one has a sample script who can share with me. Thanks (2 Replies)
Discussion started by: gkrishnag
2 Replies
Login or Register to Ask a Question