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 linux intercept commands?

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Xiaobian to share with you what linux intercepts commands, I hope you read this article after the harvest, let us explore the method together!

Linux interception commands are: 1, cut command, according to the table character or specified delimiter interception string;2, printf command, output specified content, usually used with awk command;3, awk command, you can intercept the string by space;4, sed command, the output of other commands as the output of the stream editor.

The Linux command is:

I. Cut the command

cut: Truncate a string according to a literal or specified delimiter

-d Specify delimiter

-f Specifies the truncated columns, separated by ","

Examples:

cut -d ":" -f1,3 /etc/passwd

Print and printf commands

Command format: printf "Output format Output type" "Output content"

printf: Output the specified content, usually used with awk command

%ns indicates the number of output string types

%ni indicates the number of output integer types

% m.nf indicates the type of floating point number output

print: Same as printf, but wraps when outputting strings

Examples:

printf "%s\t%s\t%s\t\n" 1 2 3

3. awk command

awk: String can be truncated by spaces

Command format: awk '{condition1}{action1}{condition2}{action2}'

BEGIN is processed before interception

END processed after interception

FS Specify delimiter

Examples:

df -h | grep vda1 | awk '{printf $1 "\t" $5}' |cut -d "%" -f1 #Use awk to count root partition usage awk 'BEGIN{print "Start counting results of Class 3"}END{print "End of results"}{print $2 "\t" $5}' student.txt cat /etc/passwd| grep /bin/bash | grep -v root | awk 'BEGIN{FS=":"}{print $1 "\t" $5}' #Find regular users in the system

IV. SED Command

1. Command format: sed [option] '[action]'

sed: stream editor that takes the output of other commands as output

-n Output only information edited by sed command

-e Multiple commands operate together, separated by ";"

-i Save modified content to original file

2. Action commands include

a appends the specified string to the specified line

i inserts the specified string before the specified line

d Delete the specified row

c Replace by line

s Replace by string format: /s/new string/old string/g

p Print line

Examples:

sed '2p' ./ sugar/student.txt #Print the second line of student.txt sed '2a hahaha' student.txt #Append the string hahahaha to the second line of the student.txt file sed '2i hahaha\xixixi' student.txt #Insert hahaha and xixixi before the second line of student.txt file sed '2,4d' student.txt #Delete lines 2 to 4 of student.txt file sed '2c no such man' student.txt #Replace the second line of student.txt with no such man sed '2s/HubuSugar/igoodful/g' student.txt #Replace HubuSugar with igoodful in student.txt file sed -e '2d;3c no such man' student.txt #Delete the second line of the student.txt file, and replace the third line with no such man. After reading this article, I believe you have a certain understanding of the commands intercepted by linux. If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!

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

Servers

Wechat

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

12
Report