+4 votes
in Operating Systems by (40.5k points)
Which Linux command should I use to delete the last row of a file?

1 Answer

+3 votes
by (56.7k points)
selected by
 
Best answer

To delete the last row from a file, you can use the 'sed' command with 'd' and '$' options.

'$' - Match the last line

'd' -  Delete pattern space 

Use the following command:

sed -i '$d' file_name

$d should be inside the single quote ('). Without a single quote, the command will give an error. If you use a double quote ("), the command will not delete the last record.


...