5

I am trying to combine cat and tail commands:

Like this:

I have file name "text1" and want to combine to file name "text2". But first I wanted to remove 7 lines from file text1 before I combine to file "text2"

     tail --lines=+7 text1 | cat  text2 > out_put 

This does not work for me on Ubuntu 12.04

Yacob
  • 515
  • 3
  • 10
  • 18

3 Answers3

9
{ tail --lines=+7 text1; cat text2; } > out_put 

or

tail --lines=+7 text1 | cat - text2 > out_put 

Passing - tells cat to read from stdin first, then from text2.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
2

Do it in two steps/commands:

tail --lines=+7 text1 > output
cat text2 >> output

Or even like this, that will perform the second if the first was successful:

tail --lines=+7 text1 > output && cat text2 >> output

Note that we use >> to append data to the file, so it will be added after the previous data existing in the file. With > we just delete everything that was there before.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
0

An alternative is to use a "here-string" (described in man bash):

cat - <<< "$(tail --lines=+3 text1)" text2 > out_put
builder-7000
  • 7,131
  • 3
  • 19
  • 43