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

Solve the 1251 error when establishing a connection between mysql and navicat

I reinstalled the computer and installed the late...

Vue Beginner's Guide: Creating the First Vue-cli Scaffolding Program

1. Vue--The first vue-cli program The development...

Mini Program implements list countdown function

This article example shares the specific code for...

Example of building a Jenkins service with Docker

Pull the image root@EricZhou-MateBookProX: docker...

Vue project realizes paging effect

The paging effect is implemented in the vue proje...

Detailed explanation of TypeScript 2.0 marked union types

Table of contents Constructing payment methods us...

How to implement insert if none and update if yes in MySql

summary In some scenarios, there may be such a re...

Detailed explanation of React component communication

Table of contents Component Communication Introdu...

Detailed explanation of how Vue components transfer values ​​to each other

Table of contents Overview 1. Parent component pa...

Native JS to implement click number game

Native JS implements the click number game for yo...

A few front-end practice summaries of Alipay's new homepage

Of course, it also includes some personal experien...

Detailed explanation of the method of comparing dates in MySQL

If there is a table product with a field add_time...