[solved] Trailing spaces

Hello People

How to check whether lines in a text file have trailing spaces or not and if a line have trailing spaces then how many trailing spaces line have?

Regards
ARvind kumar

How about:

[house@leonov] a="some text   "; b=$( echo "$a" | sed 's/[ ]*$//' ); c=$(( ${#a} - ${#b} )); echo "$c"
3
awk '/ $/ {print length - match($0, / +$/) + 1, $0}' file
1 Like

Hi Scottn Can you please briefly explain your solution..as i am not able to understand the solution properly provided by you or can you give me some link so that i can understand it .Thanks in Advance

It finds lines ending with a space (/ $/), and prints the number of spaces at the end of the line by subtracting the position of the first or all space at the end of the line (match($0, / +$/) from the length of the line itself ( length).

The best place to start is the awk man page. (if I'd have done that(!) the solution might have been easier):

1 Like

Thanks Scottn,now i understand this.My problem is solved now.Thanks a lot sir.and please tell me how to mark it as solved and close.