The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
appending to sed output of one file into the middle of file go4desperado Shell Programming and Scripting 5 02-04-2007 11:20 PM
Reading specific contents from a file and appending it to another file dnicky Shell Programming and Scripting 5 10-04-2005 02:45 AM
appending to a file in sftp borncrazy Shell Programming and Scripting 3 09-01-2004 10:23 AM
appending a file chumba UNIX for Dummies Questions & Answers 1 05-24-2001 08:09 AM
Appending out to a file Astudent UNIX for Dummies Questions & Answers 1 10-19-2000 11:17 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-02-2008
Registered User
 

Join Date: Oct 2007
Location: NYC
Posts: 6
Question appending a file using sed in ksh

i am trying to append a 5 line SGML file(file1) with a 500,000 line SGML file (file2).

file1 is a template, so i wish to preserve.
i only want to add lines 5 to the end of file2.

i have:
cp file1 temp1
sed -n '5,$p' file2 >> temp1

when i check the tail of temp1, i consistantly find the last 4 lines missing.

i have run a line count on file2 and inserted in sed -n '5,500000p' with same result.

please note, filepaths are absolute because the script runs from a seperate script folder.

can someone help?
Reply With Quote
Forum Sponsor
  #2  
Old 01-02-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
It's not clear if you want to prepend or append, but one of these should do it:

cat extra file1 > file2
cat file1 extra > file2

extra is file with the 5 new lines.
Reply With Quote
  #3  
Old 01-02-2008
Registered User
 

Join Date: Oct 2007
Location: NYC
Posts: 6
thanks for replying Perderabo, but i was probably not clear.

file one actually has 7 lines. i want to replace the first 4 lines of file2 with file1.

so i copied file1 to temp1 (new file), then tried to append the new file with lines 5 thru 548203 of file2.

everything works except that i am always missing lines 548200 to 5482003 in the new file.

i do not know how to extract lines 5 thru 548203 using cat. also, because the line count is a variable i'd prefer to not use head | tail.
Reply With Quote
  #4  
Old 01-02-2008
Registered User
 

Join Date: Oct 2007
Location: NYC
Posts: 6
nevermind...figured it out. thanks!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0