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 > Operating Systems > AIX
.
google unix.com



AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Merge text files while combining the multiple header/trailer records into one each. oordonez Shell Programming and Scripting 4 11-17-2008 11:06 PM
how to merge these two files? fedora Shell Programming and Scripting 3 02-12-2008 06:45 PM
help in merge files u263066 Shell Programming and Scripting 5 07-24-2006 03:24 AM
Is there any non graphical tool that make selective merge between text files? umen UNIX for Dummies Questions & Answers 3 08-25-2005 02:22 AM
Merge Graphics with text file schaganti Windows & DOS: Issues & Discussions 6 11-08-2004 09:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-09-2008
panchpan panchpan is offline
Registered User
  
 

Join Date: Aug 2007
Location: Australia
Posts: 115
merge text files

Hello.
Could you please help to know the command to merge multiple text files into one?
I am thinking to use:

cat f1.txt f2.txt f3.txt > f4.txt

Is it okay to use cat command for same purpose - Or could there be any disadvantage in using it?

Thank you
  #2 (permalink)  
Old 12-10-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,257
It is ok; you could just try it out and check the file afterwards. If it looks ok, cat and the redirection must have done a good job.

Since this is nothing special to AIX think about posting such kind of question into one of the more appropriate forums next time please. No offense, but since this is a very basic question UNIX for Dummies Questions & Answers - The UNIX and Linux Forums would be a good choice for it next time.
If it goes deeper into shell scripting etc. you can also post in

Shell Programming and Scripting - The UNIX and Linux Forums
UNIX for Advanced & Expert Users - The UNIX and Linux Forums
  #3 (permalink)  
Old 12-10-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Quote:
Originally Posted by panchpan View Post
Hello.
Could you please help to know the command to merge multiple text files into one?
I am thinking to use:

cat f1.txt f2.txt f3.txt > f4.txt

Is it okay to use cat command for same purpose - Or could there be any disadvantage in using it?

Thank you
No problem, that's what cat is for.

Regards
  #4 (permalink)  
Old 12-10-2008
panchpan panchpan is offline
Registered User
  
 

Join Date: Aug 2007
Location: Australia
Posts: 115
Hello - Thanks for your reply.

Now consider I have a common header 'HEADER' and trailer 'TRAILER' in all the files and I want to have their header , trailer only once in the concatenated output file. Please advice how could that be done?

Thank you
  #5 (permalink)  
Old 12-11-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
If you have the 'HEADER' at the first line and 'TRAILER' at the last line in all your files you can delete the those lines after merging the files with:

Code:
awk -v var=`wc -l < file` 'NR>1 && /HEADER/ || NR<var && /TRAILER/{next}{print}' file > newfile
First we use a variable var wich is the number of the last line (wc -l < file).
Now we print every line except the line with HEADER if it isn't the first line and the line with TRAILER if it isn't the last line.

Regards
Sponsored Links
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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