Merging File with headers | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Merging File with headers

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-18-2012
Arun Mishra Arun Mishra is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 11 June 2014, 4:30 AM EDT
Posts: 51
Thanks: 4
Thanked 0 Times in 0 Posts
Debian Merging File with headers

Hi I need to merge 4 files. The issue i am facing is all the files have headers and i do not want them in the final output file. Can anybody suggest how to do it?
Sponsored Links
    #2  
Old 12-18-2012
newbie83 newbie83 is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 19 May 2014, 3:50 PM EDT
Posts: 86
Thanks: 56
Thanked 2 Times in 1 Post
try


Code:
for FILE in *
do
        exec 5<"$FILE" 
        read LINE <&5 
        [ -z "$FIRST" ] && echo "$LINE" 
        FIRST="no"

        cat <&5 
        exec 5<&- 
        
done > merged.file

Sponsored Links
    #3  
Old 12-18-2012
Arun Mishra Arun Mishra is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 11 June 2014, 4:30 AM EDT
Posts: 51
Thanks: 4
Thanked 0 Times in 0 Posts
can i have a awk one liner for this?
    #4  
Old 12-18-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 September 2014, 12:09 PM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
try:

Code:
awk 'FNR>1' file1 file2 file3 file4 > new_file

Sponsored Links
    #5  
Old 12-18-2012
newbie83 newbie83 is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 19 May 2014, 3:50 PM EDT
Posts: 86
Thanks: 56
Thanked 2 Times in 1 Post

Code:
awk -v var=`wc -l < files ` 'NR>1 && /Header row/ {next}{print}' files

Sponsored Links
    #6  
Old 12-18-2012
Arun Mishra Arun Mishra is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 11 June 2014, 4:30 AM EDT
Posts: 51
Thanks: 4
Thanked 0 Times in 0 Posts
Thanks very much for the answers . sorry for late response i just came back from office.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Editing File Headers andysuperaudiom Shell Programming and Scripting 3 08-01-2011 10:00 AM
Multiple headers in a file gaur.deepti Shell Programming and Scripting 7 04-14-2011 09:29 AM
Merging of files with different headers to make combined headers file marut_ashu Shell Programming and Scripting 1 08-07-2009 04:10 AM
reading file headers Allasso UNIX for Dummies Questions & Answers 2 04-27-2009 03:10 PM
Remove text between headers while leaving headers intact Trones Shell Programming and Scripting 3 12-27-2008 07:06 PM



All times are GMT -4. The time now is 01:56 AM.