Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I hope to draw on the knowledge of those who know far more about scripting than I. I have two files, F1 and F2, where F2 is located in a sub-directory of F1. I need to output a new file, F3, that has the entire contents of F1, followed by the contents of F2 but excluding the first line of F2 (the contents obtained by doing 'tail +2 subdir/F2'). My attempts so far have been fruitless, so any help would be gratefully received.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted
cat "F1" > "F3"
tail +2 "subdir/F2" >> "F3"

This will write F1 into F3, and then append the tail output. It's called output redirection.

share|improve this answer
    
Is there any reason not to use cp F1 F3 for the first step? –  Dennis Williamson Jan 18 '12 at 15:38
    
@DennisWilliamson I'm not sure what file attributes cp preserves by default. But you're right, cp "F1" "F3" would also work. –  Daniel Beck Jan 18 '12 at 15:40
    
Thanks, that got me where I needed to be. –  endian Jan 18 '12 at 16:18
add comment

You can also use command grouping to obtain a one-liner:

{ cat F1; sed 1d dir/F2; } > F3
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.