Skip to main content
added 338 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Using GNU sponge to do in-place editing of file1.txt:

{ cat person1.txt; tail -n +8 file1.txt; } | sponge file1.txt

This concatenates the person1.txt file with all but the 7 first lines from the file1.txt file and saves the result into file1.txt.

With sed, you would do the same with

sed -e '1r person1.txt' -e '1,7d' file1.txt | sponge file1.txt

(you could use 8,$!d in place of 1,7d), or, if using GNU sed,

sed -i -e '1r person1.txt' -e '1,7d' file1.txt

This inserts the contents of person1.txt at the start and then skips the first seven lines from the file1.txt input file.

Using GNU sponge to do in-place editing of file1.txt:

{ cat person1.txt; tail -n +8 file1.txt; } | sponge file1.txt

This concatenates the person1.txt file with all but the 7 first lines from the file1.txt file and saves the result into file1.txt.

Using GNU sponge to do in-place editing of file1.txt:

{ cat person1.txt; tail -n +8 file1.txt; } | sponge file1.txt

This concatenates the person1.txt file with all but the 7 first lines from the file1.txt file and saves the result into file1.txt.

With sed, you would do the same with

sed -e '1r person1.txt' -e '1,7d' file1.txt | sponge file1.txt

(you could use 8,$!d in place of 1,7d), or, if using GNU sed,

sed -i -e '1r person1.txt' -e '1,7d' file1.txt

This inserts the contents of person1.txt at the start and then skips the first seven lines from the file1.txt input file.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Using GNU sponge to do in-place editing of file1.txt:

{ cat person1.txt; tail -n +8 file1.txt; } | sponge file1.txt

This concatenates the person1.txt file with all but the 7 first lines from the file1.txt file and saves the result into file1.txt.