In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
In the operation of linux, we often replace and count the strings in the file. Now let's do a collation. If there are any mistakes, please correct them.
Count the number of strings
Grep-c str filenamegrep-o str filename | wc-l
Replacement string
Replace the current line matching string
: s/oldStr/newStr
Replace all matching strings in the current file
:% s / original string / replacement string / gg
Batch replacement string
Sed-I "s / lookup field / replacement field / g" grep lookup field-rl path
-rl represents all subdirectories
Sed-I "s/new Str/old Str/g" 'grep "old Str"-rl filename'
PS:Linux common operation commands for strings
Split a string with a space
Awk'{print $1}'
Split a string with specific characters
Str=$ {str//,/}-/ / is followed by a glyph that splits the string, and the last / is followed by a space
Cut string
Cut-b |-c |-f 3-b represents bytes,-c represents characters, and-f represents the number of characters in the array following the field.
Remove specific characters from a string
Sed's /\ "/ / g's stands for substitution, the default character is replaced with blank, the character after\ is the character to be replaced, and g means replace all.
Summary
The above is the relevant operation skills of finishing strings in Linux introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message for me, and the editor will reply you in time. Thank you very much for your support to the website!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.