Related operation skills of sorting out strings in Linux
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!