Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-18-2012
Registered User
 
Join Date: Dec 2012
Posts: 47
Thanks: 2
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
Registered User
 
Join Date: Nov 2011
Posts: 53
Thanks: 33
Thanked 0 Times in 0 Posts
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
Registered User
 
Join Date: Dec 2012
Posts: 47
Thanks: 2
Thanked 0 Times in 0 Posts
can i have a awk one liner for this?
    #4  
Old 12-18-2012
Registered User
 
Join Date: Sep 2012
Location: Houston, Texas, USA
Posts: 571
Thanks: 0
Thanked 173 Times in 167 Posts
try:

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

Sponsored Links
    #5  
Old 12-18-2012
Registered User
 
Join Date: Nov 2011
Posts: 53
Thanks: 33
Thanked 0 Times in 0 Posts

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

Sponsored Links
    #6  
Old 12-18-2012
Registered User
 
Join Date: Dec 2012
Posts: 47
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks very much for the answers . sorry for late response i just came back from office.
Sponsored Links
Reply

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:43 PM.