Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concat two files 3

Status
Not open for further replies.
Sep 22, 2004
27
US
Hi Group,
I need to concatenate two files;
read in the first file to a new file
delete the last line from the new file.
append the second file to this new file stripped of last line from the first file.
I tried working arround with two cat command and tail-n1 /dev/null 2>&1 to strip off the last line. However im unsuccessful.
I would deply appreciate your help regarding this.
Thank You,
Roe.
 
One way:
(sed '$d' file1; cat file2) > newfile

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,
Thanks alot for the powerful script. That certainly did the job efficiently. However, i need to also, strip the first line from the second file before appending it. I tried manipulating the code that you had sent before but couldnt get it right:
(sed '$d' infile1; cat | sed '1d' infile2) > output.dat

Could you please point out the error in this.
Thanks again,
Roe
 
(sed '$d' infile1; sed '1d' infile2) > output.dat


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks vgersh99,
However, it strips the last line of the second file too which is not desireable. I believe sed executes the commands line by line to each of the streams.
can the sed be modified so as to strip the first line of the second file only and retain the last line?
Thanks for your help
roe
 
strange - works fine under stock Solaris' sed....

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
[tt]
awk '
NR>1&&(NR==FNR||FNR>2){print s}
{s=$0}
END{print s}' file1 file2
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top