Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A method of removing spaces or specified characters from a string in Shell

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

There are many methods on the Internet, although they are right, they do not turn out to be right. The right way is provided here.

Remove the space at the beginning

The writing of $text= "123456" # ensures that the correct results are obtained. Text= `echo $text | sed-e's / ^ [\ t] * / / g'` # these methods have not been tested. Refer to the above. # remove the spaces in the tail sed's / [\ t] * $/ / glines # delete the spaces before and after deleting the spaces, and do not delete the spaces in the middle, sed-e's / ^ [\ t] * / / g'-e's / [\ t] * $/ / glines # Delete all spaces in the string sed's / [: space:] / / g'

Of course, there is a simple way:

# replace only one text=$ {text// -} # replace all text=$ {text// / -}

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report