user1835630
user1835630

Reputation: 261

How to delete the last space at the end of each line in a text file? (shell scripts)

I have a file like this:

z E l f
A l t E^ t 
d Y s
m u s t
z E l f s
x @ w e s t
s t e t s
h E p
w i
t E n
o G @
o G @ n
m I s x i n
s t O n t

and I need to remove a space at the end of each line.

How can I do it? Thank you in advance.

Upvotes: 1

Views: 446

Answers (1)

Alper
Alper

Reputation: 13220

I assume you want to delete trailing spaces and tabs from the end of each line.

awk '{ sub(/[ \t]+$/, ""); print }' file

Upvotes: 2

Related Questions