Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've accidently distributed a line to /etc/crontab on many servers and i noticed that there's a typo in this line and i need to change it on all servers.

share|improve this question

4 Answers 4

Another option is to fix the typo rather than just delete the last line

sed -i '$ s/typotext/correcttext/ /var/spool/cron/user

You should be able to edit the crontab files directly for newer versions of cron as it checks for changes very minute.

share|improve this answer

If your sed supports in-place editing, then,

sed -i '$d' file

if not, you'll need to use a compound command such as,

cat file | sed '$d' > newfile; mv newfile file
share|improve this answer

use head

user@host$ cat <<EOF > test.txt
1
2
3
4
EOF
user@host$ head -n -1 test.txt | sponge test.txt
user@host$ cat test.txt
1
2
3
user@host$
share|improve this answer

See this forum article on unix.com for the answer:

http://www.unix.com/shell-programming-scripting/25027-delete-last-line.html

sed -e '$d' input.file > output.file

or

head -$((wc -l file | awk '{print $1}' - 1)) file

share|improve this answer
    
Please don't post just a link as an answer but give at least a summary of the info found in this link. –  Sven Oct 17 '12 at 10:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.