UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 23rd, 2004, 04:16 AM
slimanesadouki slimanesadouki is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Algeria
Posts: 2 slimanesadouki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question concatenate files ?

Hi

I want to write a UNIX shell script to concatenate 2 files:
Assume that I have File1 and File2
My need is to concatenate in the head of File2 the content of File1 without erasing File2
The same thing that do tee –a but in the head of the file not in end , is it possible ?

Thanks for your Help !

Reply With Quote
  #2  
Old December 23rd, 2004, 05:02 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,089 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 3 h 40 m 34 sec
Reputation Power: 9
your best unix friend is called 'man', so
man cat
will show you the manual pages of cat command
if you don't have man, google for 'unix man cat'

Reply With Quote
  #3  
Old December 23rd, 2004, 05:07 AM
slimanesadouki slimanesadouki is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Algeria
Posts: 2 slimanesadouki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,
with cat file1 file2 > file2
can i be sure that i dont lose changes made on file2 if the commande take time ?

Thanks

Reply With Quote
  #4  
Old December 23rd, 2004, 05:10 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,089 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 3 h 40 m 34 sec
Reputation Power: 9
that will first zeroing file2

Last edited by guggach : December 23rd, 2004 at 05:12 AM. Reason: typo

Reply With Quote
  #5  
Old December 27th, 2004, 06:06 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by slimanesadouki
Hi,
with cat file1 file2 > file2
can i be sure that i dont lose changes made on file2 if the commande take time ?

Thanks


This is not correct. Read in some tutorial about expanding of the command line. The redirection is made before sending the command to the lower structures of Unix. Your command only deletes the file2 and then catinates file1 into file2. The only possibility is to use a temporary file and then rename it:

cat file1 file2 > file3
mv file3 file2

I have made the same error many years ago too...

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > concatenate files ?


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway