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

What are the methods of string interception in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this article "string interception methods in linux", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what are the methods of string interception in linux".

String interception in Linux is very useful, and there are eight ways.

Suppose there is a variable var= https://www..com/123.htm

1. # intercept, delete the left character and retain the right character.

Echo ${var#*//}

Where var is the variable name, the # sign is the operator, and * / / means to delete the first / / sign and all characters on the left from the left.

That is, delete http://

The result is: www..com/123.htm

2. # # intercepts, deletes the left character and retains the right character.

Echo ${var##*/}

# # * / deletes the last (rightmost) / sign and all characters on the left from the left

That is, delete https://www..com/

The result is 123.htm.

3.% intercept, delete the right character and keep the left character

Echo ${var%/*}

% / * means to start on the right and delete the first / sign and the characters on the right

The result is: https://www..com

4.%% intercept, delete the right character, keep the left character

Echo ${var%%/*}

%% / * means to start from the right and delete the last (leftmost) / sign and the right character

The result is: http:

5. Start with the number of characters on the left and the number of characters

Echo ${var:0:5}

Where 0 indicates the beginning of the first character on the left, and 5 represents the total number of characters.

The result is: http:

6. Start with the first character on the left and go to the end.

Echo ${var:7}

Seven of them indicates the beginning of the eighth character on the left and the end.

The result is: www..com/123.htm

7. Start with the number of characters on the right and the number of characters

Echo ${var:0-7:3}

The 0-7 represents the seventh character on the right, and 3 indicates the number of characters.

The result is: 123

8. Start with the first character on the right and go to the end.

Echo ${var:0-7}

Indicates that it starts with the seventh character on the right and ends.

The result is: 123.htm

Note: (the first character on the left is represented by 0, and the first character on the right is represented by 0-1)

The above is about the content of this article on "what are the methods of string interception in linux?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

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

Development

Wechat

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

12
Report