Eduardo
Eduardo

Reputation: 397

Sed replace spaces and a character before end of line

I have this line:

\\Server1\A Share & Test & Check    M

I want this output:

\\Server1\A Share & Test & Check

It should end with a character and not spaces (\\Server1\A Share & Test & Check)

I tried this:

 sed -i "s/[ *\t[a-z]]*$//I" shares.txt

It removes the last letter but not the spaces.

Upvotes: 0

Views: 72

Answers (2)

Hackaholic
Hackaholic

Reputation: 19733

try this

echo "\\Server1\A Share & Test & Check    M" | sed 's/[\tA-Za-z]*$//g'

output:

echo "\\Server1\A Share & Test & Check

Upvotes: 1

Thomasleveil
Thomasleveil

Reputation: 103965

The regex you are after is \s*[a-z]*$

sed -i "s/\s*[a-z]*$//I" shares.txt

\s is for any white space character

Upvotes: 1

Related Questions