Appending 2 files skipping the header of the second file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Appending 2 files skipping the header of the second file
# 1  
Old 09-14-2011
Appending 2 files skipping the header of the second file

I have 2 files with the same header and need to append them and put the result in a 3rd file

the 2 files has the same header and while appending i want to skip the second file header and need the result to be put in a third file

Normally, this would work

Cat file1 file2 >> file3....But how do i skip the second file header?
# 2  
Old 09-14-2011
If the header is 5 lines:
Code:
( cat file1 ; tail -n +6 file2 ) >> file3

# 3  
Old 09-14-2011
header is 5 lines??? dint understand...could u pls elaborate

---------- Post updated at 02:14 PM ---------- Previous update was at 01:55 PM ----------

eg;

file1:

Code:
name place animal thing
xxx    yyy    www   ttt


file2;

Code:
name place animal thing
vvv   ssss    ssss   ssss

so when concatenating i want to skip the header of second file..my result in the 3rd file shud be,

Code:
name place animal thing
xxx    yyy    www   ttt
vvv   ssss    ssss   ssss

Moderator's Comments:
Mod Comment Please use code tags!

Last edited by radoulov; 09-15-2011 at 05:58 PM..
# 4  
Old 09-14-2011
Your header is one line, then. Use 2.
# 5  
Old 09-15-2011
Corona...Your script dint work...Can you suggest some better ideas??
# 6  
Old 09-15-2011
In what way did it "not work"? Be specific.

Code:
$ ( cat file1 ; tail -n +2 file2 )
name place animal thing
xxx yyy www ttt
vvv ssss ssss ssss

$ ( cat file1 ; tail -n +2 file2 ) > file3
$ cat file3
name place animal thing
xxx yyy www ttt
vvv ssss ssss ssss

$

---------- Post updated at 02:56 PM ---------- Previous update was at 02:49 PM ----------

Another way to do it:

Code:
$ ( cat file1 ; exec 0<file2 ; read HEADER ; cat )
name place animal thing
xxx yyy www ttt
vvv ssss ssss ssss

$ ( cat file1 ; exec 0<file2 ; read HEADER ; cat ) > file3
$ cat file3
name place animal thing
xxx yyy www ttt
vvv ssss ssss ssss

$

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. UNIX for Beginners Questions & Answers

Renaming files by appending string from within file to filename

Greetings. I am working in a Linux environment and am trying to figure out a way to rename files in a directory by appending a unique strings that appears within a certain area in those files. I have gotten as far as identifying what that particular unique string is with a command like the... (10 Replies)
Discussion started by: HLee1981
10 Replies

3. Shell Programming and Scripting

Copying multiple files and appending time stamp before file extension

Hi, I have multiple files that read: Asa.txt Bad.txt Gnu.txt And I want to rename them using awk to Asa_ddmmyytt.txt and so on ... If there is a single command or more efficient executable please share! Thanks! (4 Replies)
Discussion started by: Jesshelle David
4 Replies

4. Shell Programming and Scripting

Match in awk skipping header rows

I am trying to match $1-$7 between the two files and if a match is found then the contents of $8 in file2 and copied over. The awk I tried is below. There is also a header row in file2 that has the Chr Start End Ref Alt that does not need to be searched. Thank you :). awk awk... (3 Replies)
Discussion started by: cmccabe
3 Replies

5. Shell Programming and Scripting

Cp & skipping exiting files

// Redhat I am running a cron with cp every 15 minutes. cp /p2/arch/log/* /p2/bkp What I need is to not to copy the file again if the filename already exists under /p2/bkp The reason is that the file size under /p2/arch/log/ will be reduced (contents truncated), so I need to keep the... (10 Replies)
Discussion started by: Daniel Gate
10 Replies

6. Shell Programming and Scripting

Move only folders and skipping files

How do I move all folders and its contents from a directory A to another directory B, skipping all files in Directory A ? ---------- Post updated at 12:53 PM ---------- Previous update was at 12:42 PM ---------- Ok. Got it. mv /A/*/ /B/ (1 Reply)
Discussion started by: DHeisenberg
1 Replies

7. UNIX for Advanced & Expert Users

Appending a files contents to the end of a specific file name in several directories

Here is my dir structure: /tmp/dave/myappend.txt /tmp/dave/dir1/test.txt /tmp/dave/dir2/test.txt /tmp/dave/dir3/test.txt /tmp/dave/dir4/test.txt I want to append the contents of myappend.txt to the end of each file with the name "test.txt" in all dirs in /tmp/dave/ I have tried this:... (2 Replies)
Discussion started by: bigd213
2 Replies

8. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

9. Shell Programming and Scripting

Compare EDI files by skipping selected Segments

Hi, I wanted to compare EDI files present in Two different Directories which can be related by the file names. While comparing the EDI files i have to skip selected segments such as "ISA" "IEA" and "GS" "GE" since this may have datetime stamp and different "Sender" "Receiver" Qual. and... (3 Replies)
Discussion started by: Sivas
3 Replies

10. Shell Programming and Scripting

sed skipping the last line in a file

Hello All, I have a file like this: PART A1 PART A2 % PART B1 PART B2 The last line in the file (PART B2) does not end with a new line. i.e <EOF> immediately follows "PART B2". Here is my problem: I want to print everything after '%'. So, I tried: sed '1,/%/ d' . This works... (6 Replies)
Discussion started by: aghoras
6 Replies
Login or Register to Ask a Question