Deleting last records of a file

can you please give shell script for daleting the last 7 records of file...

no this is not a free script writing service. If you like help in learning how to write your own, that would be appropriate.

Post what you have tried so far, and point out where you are having trouble.

I am sure that you will get some good replies.

People are much more likely to assist though if you can at least show some attempt.

i have tried with the following script....

sed -n '/^$/q;p' inputfile

for writing a new file till it finds the empty record....

But...now i am trying to write a code for deleting the last 7 records (which is a trailer records and a empty records) of a file and the file name itself contains the space....

Eaxample : File Name

Export Table.csv

Can you please help in this regard....

check out 'man head' and 'man wc'

You probably already figured out how to use what the above poster said, but here's some specifics:

$ wc -l inputfile
30 <---example record count
$ head -23 inputfile > outputfile

That should do it.

I'll use the output of ls -al to demonstrate my quick and dirty method:

ls -al | tac | tail +8 | tac

The tac command is cat, backwards... it takes input and spits it out backwards by line. The command tail +x, where x is a positive integer, outputs the command's input starting at line x. Note that saying "chop off the first 7 lines" is the same as saying, "start showing output at line 8". Then, just tac it again and you're done. Like I said, this is quick and dirty... flip it upside down, chop its feet off, flip it rightside up again. Not recommended for any situation where even moderately good performance is needed! Oh, and so far as I've seen, if a system doesn't have tac, you can usually use tail -r in its place.

awk 'FNR==NR{c++;next}FNR<(c-7){print}' file file