Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove newline from end of file

Tags:

file

unix

newline

I want to remove newline \n only from end of the file in unix
e.g.

abc  
def  
ghi
​

output should be

abc  
def  
ghi

In the end of file there should not be a single \n

like image 678
jn_sum Avatar asked Dec 26 '11 11:12

jn_sum


1 Answers

You can:

perl -pe 'chomp if eof' file1 > file2

Example:

$ cat file1
abc
def
ghi
$ perl -pe 'chomp if eof' file1 > file2
$ cat file2
abc
def
ghi$ 
like image 90
Aleksandra Zalcman Avatar answered Jan 02 '23 05:01

Aleksandra Zalcman