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.
2 Answers
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.
-
Is there any reason not to use
cp F1 F3
for the first step? Commented Jan 18, 2012 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 ♦Commented Jan 18, 2012 at 15:40
You can also use command grouping to obtain a one-liner:
{ cat F1; sed 1d dir/F2; } > F3