0

I search for a moment the way in my script bash, to be able to remove the 3 last lines of a file with each call of the script.

test.sh

head -n -3 test.txt > temp.txt ; mv temp.txt test.txt

result :

head: illegal line count -- -3

test.txt - Before:

Name : Mike
Surname : Tilmen
-----------------------------------
Name : Mould
Surname : Tilmen
-----------------------------------
Name : May
Surname : Tilmen
-----------------------------------

test.txt - After (not working):

Name : Mike
Surname : Tilmen
-----------------------------------
Name : Mould
Surname : Tilmen
-----------------------------------
Paul
  • 352
  • 3
  • 6
  • 17
  • Are you on a mac? It doesn't like negative line counts. May have to switch to `sed` instead. – JNevill Nov 28 '17 at 21:47
  • works fine on my x86_64 linux, with bash version 4.4.12 – ntj Nov 28 '17 at 21:47
  • see https://stackoverflow.com/questions/13380607/how-to-use-sed-to-remove-the-last-n-lines-of-a-file for solution. – ntj Nov 28 '17 at 21:48

0 Answers0