The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep help, how do i rewrite this weezybaby Shell Programming and Scripting 5 01-31-2008 07:57 PM
need to extract info from log files kirantalla AIX 7 08-15-2007 11:33 PM
How can I get multiple info from different files efernandes Shell Programming and Scripting 3 02-07-2007 06:54 PM
How do I rewrite to use a while instead of find? goodmis Shell Programming and Scripting 4 02-06-2007 02:20 PM
Apache Rewrite help! hassan2 UNIX for Advanced & Expert Users 1 11-11-2002 01:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2003
strok
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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
  #2 (permalink)  
Old 03-28-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
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 (permalink)  
Old 03-28-2003
perleo perleo is offline
Registered User
  
 

Join Date: Aug 2002
Location: Ireland
Posts: 139
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 (permalink)  
Old 03-28-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
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 (permalink)  
Old 03-28-2003
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
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 (permalink)  
Old 03-29-2003
strok
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
the perl one is good enough

thanks alot
  #7 (permalink)  
Old 03-29-2003
strok
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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.....
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0