How to delete the last character of the last line of a file?

I have this set of lines in a file:

{info},
{info},
{info},
{info},

and I want this file to be like this without the last ",":

{info},
{info},
{info},
{info}

How to do this in bash? Any idea?

+4
source share
2 answers

You can use sed:

sed '$ s/.$//' your_file
  • First, I $must report sedonly the last line
  • sintended to be "replaced", pay attention to the empty line between the last two /s
  • .$ is a regular expression that matches the last character in the file

, , /, , :

sed '$ s-.$--' your_file
+10

vim : replace : s, . vim-built in - http://vim.wikia.com/wiki/Search_and_replace

, :$s/.$//g

+1

Source: https://habr.com/ru/post/1615637/


All Articles