0

I have two text files, file_1 and file_2. How can I concatenate file_2, from line 20 onwards, with file_1?

3
  • What do you mean by "concatenate"? Apr 6, 2017 at 17:43
  • if i do: cat file_1 file_2 if combines both files completely. i don't want to add the entire file_2 to file_1, just from line 20 onwards... Apr 6, 2017 at 17:50
  • 1
    Then you want something like this: { cat file_1; sed 1,19d file_2 } >result. Apr 6, 2017 at 17:51

2 Answers 2

0

Use ed, man! !man ed!

ed -s file_1 <<< $'r !sed -e 1,19d file_2\nwq'
  • -s = suppress diagnostic output
  • <<< = redirect ed's input to be the following here-string
  • $' ... ' = supply the following quoted string
  • r = tell ed to read from the following ...
  • !sed -e 1,19d file_2 = command, instead of a file; ask sed to show us everything except lines 1 through 19 (delete them) of file_2
  • wq = write and quit!
1
  • Also works with ex (no need for the -s there)
    – Jeff Schaller
    Apr 6, 2017 at 18:07
0

If I understand your question correctly, you want lines 20 onwards from file_2, followed by file_1's contents. I would do this:

( tail -n +20 file_2; cat file_1 ) > file_3
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .