Tips for organizing strings in Linux

Tips for organizing strings in Linux

In Linux operations, we often replace and count strings in files. Let's do a summary now. If there are any mistakes, please criticize and correct them.

Count the number of strings

grep -c str filename
grep -o str filename |wc -l

Replace String

Replace the current line with the matching string

:s/oldStr/newStr

Replace all matches in the current file

:%s/original string/replacement string/gg

Batch replace string

sed -i "s/search field/replace field/g" grep search field-rl path

-rl means all subdirectories

sed -i "s/new Str/old Str/g" 'grep "old Str" -rl filename'

PS: Linux commonly used string operation commands

Split string by space

awk '{print $1}'

Split a string at specific characters

str=${str//,/ } ——————–//后面是分割字符串的標志符號,最后一個/后面還有一個空格

Cutting a string

cut -b|-c|-f 3 ———————–b代表字節,-c代表字符,-f代表域后面的數組是第幾個字符

Remove specific characters from a string

sed 's/\”//g' s代表替換,默認字符被替換為空,\后面的字符是要被替換的字符,g表示全部替換

Summarize

The above is the relevant operation skills for organizing strings in Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Linux special characters and their functions
  • How to change the character set encoding to UTF8 in MySQL 5.5/5.6 under Linux
  • Linux C string replacement function example detailed explanation
  • How to concatenate strings in Linux shell script
  • Linux kernel device driver virtual file system notes
  • Linux kernel device driver system call notes
  • Linux kernel device driver kernel debugging technical notes collation
  • Linux kernel device driver kernel linked list usage notes
  • Linux kernel device driver proc file system notes
  • Linux kernel device driver advanced character device driver notes
  • Linux kernel device driver Linux kernel module loading mechanism notes summary
  • Linux kernel device driver address mapping notes
  • Linux kernel device driver Linux kernel basic notes summary
  • Linux kernel device driver character device driver notes

<<:  MySQL uses init-connect to increase the implementation of access audit function

>>:  Vue project configures webpack-obfuscator to implement code encryption and obfuscation

Recommend

MySQL 8.0.25 installation and configuration method graphic tutorial

The latest download and installation tutorial of ...

How to improve Idea startup speed and solve Tomcat log garbled characters

Table of contents Preface Idea startup speed Tomc...

Detailed explanation of Deepin using docker to install mysql database

Query the MySQL source first docker search mysql ...

How to start Vue project with M1 pro chip

Table of contents introduction Install Homebrew I...

PHP-HTMLhtml important knowledge points notes (must read)

1. Use frameset, frame and iframe to realize mult...

Detailed explanation of count without filter conditions in MySQL

count(*) accomplish 1. MyISAM: Stores the total n...

CSS writing format, detailed explanation of the basic structure of a mobile page

1. CSS writing format 1. Inline styles You can wr...

Analysis of the reasons why MySQL field definitions should not use null

Why is NULL so often used? (1) Java's null Nu...

Data Structure - Tree (III): Multi-way Search Tree B-tree, B+ tree

Multi-way search tree Height of a complete binary...

How to generate a unique server-id in MySQL

Preface We all know that MySQL uses server-id to ...

How to use Vue cache function

Table of contents Cache function in vue2 Transfor...

Mini Programs enable product attribute selection or specification selection

This article shares the specific code for impleme...