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
Merge files of differrent size with one field common in both files using awk shashi1982 Shell Programming and Scripting 2 03-03-2009 07:12 AM
how to merge these two files? fedora Shell Programming and Scripting 3 02-12-2008 06:45 PM
use of sed over cat to merge files miwinter UNIX for Advanced & Expert Users 2 11-28-2007 01:36 PM
How to merge files lestat_ecuador Shell Programming and Scripting 3 06-07-2007 06:45 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

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 04-21-2009
skumre skumre is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 2
how to merge selective content between files using awk?

Hello,

I'm new to awk. I've 2 files where H stands for header and T for trailer. The number following T gives the record count in a file.

file 1 looks like this:
H|A|B|C
1|2|3
1|2|4
2|3|5
T|3

file 2 looks like this:
H|A|B|C
4|5|6
7|8|9
T|2

Need to merge the above 2 files such that the new file looks like this:

H|A|B|C
1|2|3
1|2|4
2|3|5
4|5|6
7|8|9
T|5

Any help is greatly appreciated.
  #2 (permalink)  
Old 04-21-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Code:
nawk -F'|' '
NR==1
$1!="H" && $1!="T"
$1=="T" {tot+=$2}
END { print "T" OFS tot}' OFS='|' file1 file2
  #3 (permalink)  
Old 04-22-2009
skumre skumre is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 2
Thanks a bunch for your help.
Sponsored Links
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 03:01 AM.


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