![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. Shell Script Page. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| delete first 100 lines from a file | salaathi | SUN Solaris | 3 | 11-15-2007 12:01 AM |
| delete first 100 lines rather than zero out of file | thepurple | SUN Solaris | 7 | 11-14-2007 09:35 AM |
| delete the lines from file | sameersam | Shell Programming and Scripting | 2 | 04-03-2006 10:32 PM |
| Delete lines in a file | umal | Shell Programming and Scripting | 6 | 02-08-2006 09:08 AM |
| delete all lines in file | strok | UNIX for Dummies Questions & Answers | 6 | 03-11-2002 06:27 PM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I tried using the command 'tac' . i get an error command not 'found'.. how do delete the last three lines from the file..please help
|
| Forum Sponsor | ||
|
|
|
|||
|
If you know the number of lines, subtract three and print up through that number.
Radoulov's solutions are superior, as usual, although they will read the entire file into memory at once, whereas the following basically operates the file a line at a time. Code:
lines=$(wc -l <inputfile) wanted=`expr $lines - 3` head -n $wanted inputfile >outputfile |