重新安装WordPress 如何备份/seo的作用是什么

重新安装WordPress 如何备份,seo的作用是什么,深圳公安门户网站官网,比wordpress好的工具大数据技术之Shell(超级详细) 第1章 Shell概述 Shell 是一种脚本语言,用于在操作系统的命令行界面(CLI)下执行命令和脚本。在大数据领域,Shell 脚本常用于编写数据处理和分析任务的自动化脚本&#xff0c…

大数据技术之Shell(超级详细)

第1章 Shell概述

Shell 是一种脚本语言,用于在操作系统的命令行界面(CLI)下执行命令和脚本。在大数据领域,Shell 脚本常用于编写数据处理和分析任务的自动化脚本,以便快速而有效地处理大规模的数据集。
在这里插入图片描述

下面详细介绍 Shell 在大数据技术中的应用。
Shell 脚本编程:Shell 脚本是一种文本文件,其中包含一系列命令和逻辑控制语句。通过编写 Shell 脚本,可以利用 Shell 的强大功能来处理大数据。例如,可以编写循环结构和条件判断语句,实现数据的遍历、筛选和转换。Shell 脚本还支持变量和函数,使得编写复杂的数据处理逻辑更加方便。

数据清洗和转换:在大数据处理中,往往需要对原始数据进行清洗和转换,以便进行后续的分析和建模。Shell 提供了强大的文本处理功能,可以使用各种命令和技巧来处理和转换文本数据。通过 Shell 脚本,可以自动化地执行数据清洗任务,例如去除重复记录、替换无效值、提取特定字段等。

批量处理:Shell 脚本能够批量处理大规模的数据集,因为它可以通过命令行界面一次执行多个命令或任务。在大数据处理中,通过编写 Shell 脚本,可以批量执行数据处理任务、数据导入导出任务和数据分析任务,提高效率和减少工作量。例如,可以编写一个脚本,实现自动化地从源数据库中抽取数据,进行清洗和转换,然后导入到目标数据库中。

任务调度:在大数据处理中,任务调度是非常重要的,因为需要按照特定的时间表和顺序执行不同的数据处理任务。Shell 脚本可以与任务调度工具(如 cron 或 Control-M)集成,实现定时和自动化地执行数据处理任务。通过在 Shell 脚本中设置计划任务,可以实现定期执行数据处理、备份、数据迁移等任务,确保数据处理过程的稳定运行。

系统管理和监控:Shell 脚本在大数据技术中还可以用于系统管理和监控。通过编写脚本,可以自动化管理大数据平台的各个组件和节点。例如,可以编写一个脚本来监控集群的状态,检查节点的可用性和负载情况,并根据需要采取相应的措施。同时,也可以编写脚本来自动化安装和配置大数据组件,提高系统管理的效率。

实际一点,大数据程序员为什么要学习Shell呢?

1)需要看懂运维人员编写的Shell程序。

2)偶尔会编写一些简单Shell程序来管理集群、提高开发效率。

在这里插入图片描述

2 Shel解析器

(1)Linux提供的Shell解析器有:

[atguigu@hadoop101 ~]$ cat /etc/shells /bin/sh/bin/bash/sbin/nologin/bin/dash/bin/tcsh/bin/csh

(2)bash和sh的关系

[atguigu@hadoop101 bin]$ ll | grep bash-rwxr-xr-x. 1 root root 941880 5月  11 2016 bashlrwxrwxrwx. 1 root root    4 5月  27 2017 sh -> bash

(3)Centos默认的解析器是bash

[atguigu@hadoop102 bin]$ echo $SHELL/bin/bash

3 Shell脚本入门

1.脚本格式

脚本以#!/bin/bash开头(指定解析器)

2.第一个Shell脚本:helloworld

(1)需求:创建一个Shell脚本,输出helloworld

(2)案例实操:

[atguigu@hadoop101 datas]$ touch helloworld.sh[atguigu@hadoop101 datas]$ vi helloworld.sh

在helloworld.sh中输入如下内容

\#!/bin/bashecho "helloworld"

(3)脚本的常用执行方式

第一种:采用bash或sh+脚本的相对路径或绝对路径(不用赋予脚本+x权限)

​ sh+脚本的相对路径

[atguigu@hadoop101 datas]$ sh helloworld.sh Helloworld

​ sh+脚本的绝对路径

[atguigu@hadoop101 datas]$ sh /home/atguigu/datas/helloworld.sh helloworld

​ bash+脚本的相对路径

[atguigu@hadoop101 datas]$ bash helloworld.sh Helloworld

​ bash+脚本的绝对路径

[atguigu@hadoop101 datas]$ bash /home/atguigu/datas/helloworld.sh Helloworld

第二种:采用输入脚本的绝对路径或相对路径执行脚本(必须具有可执行权限+x)

(a)首先要赋予helloworld.sh 脚本的+x权限

[atguigu@hadoop101 datas]$ chmod 777 helloworld.sh

(b)执行脚本

相对路径

[atguigu@hadoop101 datas]$ ./helloworld.sh Helloworld

绝对路径

[atguigu@hadoop101 datas]$ /home/atguigu/datas/helloworld.sh Helloworld

注意:第一种执行方法,本质是bash解析器帮你执行脚本,所以脚本本身不需要执行权限。第二种执行方法,本质是脚本需要自己执行,所以需要执行权限。

3.第二个Shell脚本:多命令处理

(1)需求:

在/home/atguigu/目录下创建一个banzhang.txt,在banzhang.txt文件中增加“I love cls”。

(2)案例实操:

[atguigu@hadoop101 datas]$ touch batch.sh[atguigu@hadoop101 datas]$ vi batch.sh

在batch.sh中输入如下内容

\#!/bin/bashcd /home/atguigutouch cls.txtecho "I love cls" >>cls.txt

4 Shell中的变量

4.1 系统****变量

\1. 常用系统变量

H O M E 、 HOME、 HOMEPWD、 S H E L L 、 SHELL、 SHELLUSER等

2.案例实操

(1)查看系统变量的值

[atguigu@hadoop101 datas]$ echo $HOME/home/atguigu

(2)显示当前Shell中所有变量:set

[atguigu@hadoop101 datas]$ setBASH=/bin/bashBASH_ALIASES=()BASH_ARGC=()BASH_ARGV=()

4.2 自定义****变量

1.基本语法

(1)定义变量:变量=值

(2)撤销变量:unset 变量

(3)声明静态变量:readonly变量,注意:不能unset

2.变量定义规则

​ (1)变量名称可以由字母、数字和下划线组成,但是不能以数字开头,环境变量名建议大写。

​ (2)等号两侧不能有空格

​ (3)在bash中,变量默认类型都是字符串类型,无法直接进行数值运算。

​ (4)变量的值如果有空格,需要使用双引号或单引号括起来。

3.案例实操

​ (1)定义变量A

[atguigu@hadoop101 datas]$ A=5[atguigu@hadoop101 datas]$ echo $A5

​ (2)给变量A重新赋值

[atguigu@hadoop101 datas]$ A=8[atguigu@hadoop101 datas]$ echo $A8

​ (3)撤销变量A

[atguigu@hadoop101 datas]$ unset A[atguigu@hadoop101 datas]$ echo $A

​ (4)声明静态的变量B=2,不能unset

[atguigu@hadoop101 datas]$ readonly B=2[atguigu@hadoop101 datas]$ echo $B2
[atguigu@hadoop101 datas]$ B=9-bash: B: readonly variable

​ (5)在bash中,变量默认类型都是字符串类型,无法直接进行数值运算

[atguigu@hadoop102 ~]$ C=1+2[atguigu@hadoop102 ~]$ echo $C1+2

(6)变量的值如果有空格,需要使用双引号或单引号括起来

[atguigu@hadoop102 ~]$ D=I love banzhang-bash: world: command not found
[atguigu@hadoop102 ~]$ D="I love banzhang"[atguigu@hadoop102 ~]$ echo $AI love banzhang

​ (7)可把变量提升为全局环境变量,可供其他Shell程序使用

export 变量名

[atguigu@hadoop101 datas]$ vim helloworld.sh

在helloworld.sh文件中增加echo $B

#!/bin/bash

echo “helloworld”

echo $B

[atguigu@hadoop101 datas]$ ./helloworld.sh

Helloworld

发现并没有打印输出变量B的值。

[atguigu@hadoop101 datas]$ export B

[atguigu@hadoop101 datas]$ ./helloworld.sh

helloworld

2

4.3 特殊变量:$n

1.基本语法

​ $n (功能描述:n为数字,$0代表该脚本名称,$1- 9 代表第一到第九个参数,十以上的参数,十以上的参数需要用大括号包含,如 9代表第一到第九个参数,十以上的参数,十以上的参数需要用大括号包含,如 9代表第一到第九个参数,十以上的参数,十以上的参数需要用大括号包含,如{10})

2.案例实操

(1)输出该脚本文件名称、输入参数1和输入参数2 的值

[atguigu@hadoop101 datas]$ touch parameter.sh

[atguigu@hadoop101 datas]$ vim parameter.sh

#!/bin/bash

echo “$0 $1 $2”

[atguigu@hadoop101 datas]$ chmod 777 parameter.sh

[atguigu@hadoop101 datas]$ ./parameter.sh cls xz

./parameter.sh cls xz

4.4 特殊变量:$#

1.基本语法

​ $# (功能描述:获取所有输入参数个数,常用于循环)。

2.案例实操

(1)获取输入参数的个数

[atguigu@hadoop101 datas]$ vim parameter.sh

#!/bin/bash

echo “$0 $1 $2”

echo $#

[atguigu@hadoop101 datas]$ chmod 777 parameter.sh

[atguigu@hadoop101 datas]$ ./parameter.sh cls xz

parameter.sh cls xz

2

4.5 特殊变量:$ 、@

1.基本语法

​$(功能描述:这个变量代表命令行中所有的参数,$把所有的参数看成一个整体)

@ (功能描述:这个变量也代表命令行中所有的参数,不过 @ (功能描述:这个变量也代表命令行中所有的参数,不过 @(功能描述:这个变量也代表命令行中所有的参数,不过@把每个参数区分对待)

2.案例实操

(1)打印输入的所有参数

[atguigu@hadoop101 datas]$ vim parameter.sh

#!/bin/bash

echo “$0 $1 $2”

echo $#

echo $*

echo $@

[atguigu@hadoop101 datas]$ bash parameter.sh 1 2 3

parameter.sh 1 2

3

1 2 3

1 2 3

4.6 特殊变量$

1.基本语法

$? (功能描述:最后一次执行的命令的返回状态。如果这个变量的值为0,证明上一个命令正确执行;如果这个变量的值为非0(具体是哪个数,由命令自己来决定),则证明上一个命令执行不正确了。)

2.案例实操

​ (1)判断helloworld.sh脚本是否正确执行

[atguigu@hadoop101 datas]$ ./helloworld.sh

hello world

[atguigu@hadoop101 datas]$ echo $?

0

5 运算符

1.基本语法

(1)“ ( ( 运算式 ) ) ”或“ ((运算式))”或“ ((运算式))[运算式]”

(2)expr + , - , *, /, % 加,减,乘,除,取余

注意:expr运算符间要有空格

2.案例实操:

(1)计算3+2的值

[atguigu@hadoop101 datas]$ expr 2 + 3

5

(2)计算3-2的值

[atguigu@hadoop101 datas]$ expr 3 - 2

1

(3)计算(2+3)X4的值

​ (a)expr一步完成计算

[atguigu@hadoop101 datas]$ expr expr 2 + 3 * 4

20

(b)采用$[运算式]方式

[atguigu@hadoop101 datas]# S=$[(2+3)*4]

[atguigu@hadoop101 datas]# echo $S

6 条件判断

1.基本语法

[ condition ](注意condition前后要有空格)

注意:条件非空即为true,[ atguigu ]返回true,[] 返回false。

\2. 常用判断条件

(1)两个整数之间比较

= 字符串比较

-lt 小于(less than) -le 小于等于(less equal)

-eq 等于(equal) -gt 大于(greater than)

-ge 大于等于(greater equal) -ne 不等于(Not equal)

(2)按照文件权限进行判断

-r 有读的权限(read) -w 有写的权限(write)

-x 有执行的权限(execute)

(3)按照文件类型进行判断

-f 文件存在并且是一个常规的文件(file)

-e 文件存在(existence) -d 文件存在并是一个目录(directory)

3.案例实操

​ (1)23是否大于等于22

[atguigu@hadoop101 datas]$ [ 23 -ge 22 ]

[atguigu@hadoop101 datas]$ echo $?

0

​ (2)helloworld.sh是否具有写权限

[atguigu@hadoop101 datas]$ [ -w helloworld.sh ]

[atguigu@hadoop101 datas]$ echo $?

0

​ (3)/home/atguigu/cls.txt目录中的文件是否存在

[atguigu@hadoop101 datas]$ [ -e /home/atguigu/cls.txt ]

[atguigu@hadoop101 datas]$ echo $?

1

(4)多条件判断(&& 表示前一条命令执行成功时,才执行后一条命令,|| 表示上一条命令执行失败后,才执行下一条命令)

[atguigu@hadoop101 ~]$ [ condition ] && echo OK || echo notok

OK

[atguigu@hadoop101 datas]$ [ condition ] && [ ] || echo notok

notok

7 流程控制**(重点)**

7.1 if 判断

1.基本语法

if [ 条件判断式 ];then

程序

fi

或者

if [ 条件判断式 ]

then

程序

fi

​ 注意事项:

(1)[ 条件判断式 ],中括号和条件判断式之间必须有空格

(2)if后要有空格

2.案例实操

(1)输入一个数字,如果是1,则输出banzhang zhen shuai,如果是2,则输出cls zhen mei,如果是其它,什么也不输出。

[atguigu@hadoop101 datas]$ touch if.sh

[atguigu@hadoop101 datas]$ vim if.sh

#!/bin/bash

if [ $1 -eq “1” ]

then

​ echo “banzhang zhen shuai”

elif [ $1 -eq “2” ]

then

​ echo “cls zhen mei”

fi

[atguigu@hadoop101 datas]$ chmod 777 if.sh

[atguigu@hadoop101 datas]$ ./if.sh 1

banzhang zhen shuai

7.2 case 语句

1.基本语法

case $变量名 in

“值1”)

如果变量的值等于值1,则执行程序1

;;

“值2”)

如果变量的值等于值2,则执行程序2

;;

…省略其他分支…

*)

如果变量的值都不是以上的值,则执行此程序

;;

esac

注意事项:

\1) case行尾必须为单词“in”,每一个模式匹配必须以右括号“)”结束。

\2) 双分号“*;;*”表示命令序列结束,相当于java中的break。

\3) 最后的“*)”表示默认模式,相当于java中的default。

2.案例实操

(1)输入一个数字,如果是1,则输出banzhang,如果是2,则输出cls,如果是其它,输出renyao。

[atguigu@hadoop101 datas]$ touch case.sh

[atguigu@hadoop101 datas]$ vim case.sh

!/bin/bash

case $1 in

“1”)

​ echo “banzhang”

;;

“2”)

​ echo “cls”

;;

*)

​ echo “renyao”

;;

esac

[atguigu@hadoop101 datas]$ chmod 777 case.sh

[atguigu@hadoop101 datas]$ ./case.sh 1

1

7.3 for 循环

1.基本语法1

​ for (( 初始值;循环控制条件;变量变化 ))

do

程序

done

2.案例实操

(1)从1加到100

[atguigu@hadoop101 datas]$ touch for1.sh

[atguigu@hadoop101 datas]$ vim for1.sh

#!/bin/bash

s=0

for((i=0;i<=100;i++))

do

​ s= [ [ [s+$i]

done

echo $s

[atguigu@hadoop101 datas]$ chmod 777 for1.sh

[atguigu@hadoop101 datas]$ ./for1.sh

“5050”

3.基本语法2

for 变量 in 值1 值2 值3…

do

程序

done

4.案例实操

​ (1)打印所有输入参数

[atguigu@hadoop101 datas]$ touch for2.sh

[atguigu@hadoop101 datas]$ vim for2.sh

#!/bin/bash

#打印数字

for i in $*

do

echo "ban zhang love $i "

done

[atguigu@hadoop101 datas]$ chmod 777 for2.sh

[atguigu@hadoop101 datas]$ bash for2.sh cls xz bd

ban zhang love cls

ban zhang love xz

ban zhang love bd

(2)比较 ∗ 和 *和 @区别

(a) ∗ 和 *和 @都表示传递给函数或脚本的所有参数,不被双引号“”包含时,都以$1 2 … 2 … 2n的形式输出所有参数。

[atguigu@hadoop101 datas]$ touch for.sh[atguigu@hadoop101 datas]$ vim for.sh #!/bin/bash for i in $*do echo "ban zhang love $i "done for j in $@do echo "ban zhang love j " d o n e [ a t g u i g u @ h a d o o p 101 d a t a s ] j"done [atguigu@hadoop101 datas] j"done[atguigu@hadoop101datas] bash for.sh cls xz bdban zhang love cls ban zhang love xz ban zhang love bd ban zhang love clsban zhang love xzban zhang love bd

(b)当它们被双引号“”包含时,“$*”会将所有的参数作为一个整体,以“$1 2 … 2 … 2n”的形式输出所有参数;“$@”会将各个参数分开,以“$1” “ 2 ” … ” 2”…” 2”n”的形式输出所有参数。

[atguigu@hadoop101 datas]$ vim for.sh

#!/bin/bash

for i in “$*”

#$*中的所有参数看成是一个整体,所以这个for循环只会循环一次

​ do

​ echo “ban zhang love $i”

​ done

for j in “$@”

# @ 中的每个参数都看成是独立的,所以“ @中的每个参数都看成是独立的,所以“ @中的每个参数都看成是独立的,所以@”中有几个参数,就会循环几次

​ do

​ echo “ban zhang love $j”

done

[atguigu@hadoop101 datas]$ chmod 777 for.sh

[atguigu@hadoop101 datas]$ bash for.sh cls xz bd

ban zhang love cls xz bd

ban zhang love cls

ban zhang love xz

ban zhang love bd

7.4 while 循环

1.基本语法

while [ 条件判断式 ]

do

程序

done

2.案例实操

​ (1)从1加到100

[atguigu@hadoop101 datas]$ touch while.sh

[atguigu@hadoop101 datas]$ vim while.sh

#!/bin/bash

s=0

i=1

while [ $i -le 100 ]

do

​ s= [ [ [s+$i]

​ i= [ [ [i+1]

done

echo $s

[atguigu@hadoop101 datas]$ chmod 777 while.sh

[atguigu@hadoop101 datas]$ ./while.sh

5050

8 read读取控制台输入

1.基本语法

​ read(选项)(参数)

​ 选项:

-p:指定读取值时的提示符;

-t:指定读取值时等待的时间(秒)。

参数

​ 变量:指定读取值的变量名

2.案例实操

​ (1)提示7秒内,读取控制台输入的名称

[atguigu@hadoop101 datas]$ touch read.sh
[atguigu@hadoop101 datas]$ vim read.sh
\#!/bin/bashread -t 7 -p "Enter your name in 7 seconds " NAMEecho $NAME
[atguigu@hadoop101 datas]$ ./read.sh Enter your name in 7 seconds xiaozexiaoze

9 函数

9.1 系统函数

1.basename基本语法

basename [string / pathname] [suffix] (功能描述:basename命令会删掉所有的前缀包括最后一个(‘/’)字符,然后将字符串显示出来。

选项:

suffix为后缀,如果suffix被指定了,basename会将pathname或string中的suffix去掉。

2.案例实操

(1)截取该/home/atguigu/banzhang.txt路径的文件名称

[atguigu@hadoop101 datas]$ basename /home/atguigu/banzhang.txt banzhang.txt
[atguigu@hadoop101 datas]$ basename /home/atguigu/banzhang.txt .txtbanzhang
  1. dirname基本语法

​ dirname 文件绝对路径 (功能描述:从给定的包含绝对路径的文件名中去除文件名(非目录的部分),然后返回剩下的路径(目录的部分))

4.案例实操

(1)获取banzhang.txt文件的路径

[atguigu@hadoop101 ~]$ dirname /home/atguigu/banzhang.txt /home/atguigu

9.2 自定义函数

1.基本语法

[ function ] funname[()]{​	Action;[return int;]}funname

2.经验技巧

​ (1)必须在调用函数地方之前,先声明函数,shell脚本是逐行运行。不会像其它语言一样先编译。

​ (2)函数返回值,只能通过$?系统变量获得,可以显示加:return返回,如果不加,将以最后一条命令运行结果,作为返回值。return后跟数值n(0-255)

3.案例实操

​ (1)计算两个输入参数的和

[atguigu@hadoop101 datas]$ touch fun.sh[atguigu@hadoop101 datas]$ vim fun.sh
\#!/bin/bashfunction sum(){s=0s=$[ $1 + $2 ]echo "$s"}read -p "Please input the number1: " n1;read -p "Please input the number2: " n2;sum $n1 $n2;

[atguigu@hadoop101 datas]$ chmod 777 fun.sh

[atguigu@hadoop101 datas]$ ./fun.sh

Please input the number1: 2

Please input the number2: 5

7

10 Shell工具(重点)

10**.1** cut

cut的工作就是“剪”,具体的说就是在文件中负责剪切数据用的。cut 命令从文件的每一行剪切字节、字符和字段并将这些字节、字符和字段输出。

1.基本用法

cut [选项参数] filename

说明:默认分隔符是制表符

2.选项参数说明

表1-55

选项参数功能
-f列号,提取第几列
-d分隔符,按照指定分隔符分割列

3.案例实操

(0)数据准备

[atguigu@hadoop101 datas]$ touch cut.txt

[atguigu@hadoop101 datas]$ vim cut.txt

dong shen

guan zhen

wo wo

lai lai

le le

(1)切割cut.txt第一列

[atguigu@hadoop101 datas]$ cut -d " " -f 1 cut.txt

dong

guan

wo

lai

le

(2)切割cut.txt第二、三列

[atguigu@hadoop101 datas]$ cut -d " " -f 2,3 cut.txt

shen

zhen

wo

lai

le

(3)在cut.txt文件中切割出guan

[atguigu@hadoop101 datas]$ cat cut.txt | grep “guan” | cut -d " " -f 1

guan

(4)选取系统PATH变量值,第2个“:”开始后的所有路径:

[atguigu@hadoop101 datas]$ echo $PATH

/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/atguigu/bin

[atguigu@hadoop102 datas]$ echo $PATH | cut -d: -f 2-

/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/atguigu/bin

(5)切割ifconfig 后打印的IP地址

[atguigu@hadoop101 datas]$ ifconfig eth0 | grep “inet addr” | cut -d: -f 2 | cut -d" " -f1

192.168.1.102

10.2 sed

sed是一种流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”,接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非你使用重定向存储输出。

\1. 基本用法

sed [选项参数] ‘command’ filename

\2. 选项参数说明

表1-56

选项参数功能
-e直接在指令列模式上进行sed的动作编辑。

\3. 命令功能描述

表1-57

命令功能描述
a新增,a的后面可以接字串,在下一行出现
d删除
s查找并替换

\4. 案例实操

(0)数据准备

[atguigu@hadoop102 datas]$ touch sed.txt[atguigu@hadoop102 datas]$ vim sed.txtdong shenguan zhenwo  wolai  laile  le

(1)将“mei nv”这个单词插入到sed.txt第二行下,打印。

[atguigu@hadoop102 datas]$ sed '2a mei nv' sed.txt dong shenguan zhenmei nvwo  wolai  laile  le
[atguigu@hadoop102 datas]$ cat sed.txt dong shenguan zhenwo  wolai  laile  le

注意:文件并没有改变

(2)删除sed.txt文件所有包含wo的行

[atguigu@hadoop102 datas]$ sed '/wo/d' sed.txtdong shenguan zhenlai  laile  le

(3)将sed.txt文件中wo替换为ni

[atguigu@hadoop102 datas]$ sed 's/wo/ni/g' sed.txt dong shenguan zhenni  nilai  laile  le

注意:‘g’表示global,全部替换

(4)将sed.txt文件中的第二行删除并将wo替换为ni

[atguigu@hadoop102 datas]$ sed -e '2d' -e 's/wo/ni/g' sed.txt dong shenni  nilai  laile  le

10.3 awk

一个强大的文本分析工具,把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行分析处理。

\1. 基本用法

awk [选项参数] ‘pattern1{action1} pattern2{action2}…’ filename

pattern:表示AWK在数据中查找的内容,就是匹配模式

action:在找到匹配内容时所执行的一系列命令

\2. 选项参数说明

表1-55

选项参数功能
-F指定输入文件折分隔符
-v赋值一个用户定义变量

\3. 案例实操

(0)数据准备

[atguigu@hadoop102 datas]$ sudo cp /etc/passwd ./

(1)搜索passwd文件以root关键字开头的所有行,并输出该行的第7列。

[atguigu@hadoop102 datas]$ awk -F: '/^root/{print $7}' passwd /bin/bash

(2)搜索passwd文件以root关键字开头的所有行,并输出该行的第1列和第7列,中间以“,”号分割。

[atguigu@hadoop102 datas]$ awk -F: '/^root/{print $1","$7}' passwd root,/bin/bash

注意:只有匹配了pattern的行才会执行action

(3)只显示/etc/passwd的第一列和第七列,以逗号分割,且在所有行前面添加列名user,shell在最后一行添加"dahaige,/bin/zuishuai"。

[atguigu@hadoop102 datas]$ awk -F : 'BEGIN{print "user, shell"} {print $1","$7} END{print "dahaige,/bin/zuishuai"}' passwduser, shellroot,/bin/bashbin,/sbin/nologin。。。atguigu,/bin/bashdahaige,/bin/zuishuai

注意:BEGIN 在所有数据读取行之前执行;END 在所有数据执行之后执行。

(4)将passwd文件中的用户id增加数值1并输出

[atguigu@hadoop102 datas]$ awk -v i=1 -F: '{print $3+i}' passwd1234

\4. awk的内置变量

表1-56

变量说明
FILENAME文件名
NR已读的记录数
NF浏览记录的域的个数(切割后,列的个数)

\5. 案例实操

(1)统计passwd文件名,每行的行号,每行的列数

[atguigu@hadoop102 datas]$ awk -F: '{print "filename:"  FILENAME ", linenumber:" NR  ",columns:" NF}' passwd filename:passwd, linenumber:1,columns:7filename:passwd, linenumber:2,columns:7filename:passwd, linenumber:3,columns:7

​ (2)切割IP

[atguigu@hadoop102 datas]$ ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk -F " " '{print $1}' 192.168.1.102

​ (3)查询sed.txt中空行所在的行号

[atguigu@hadoop102 datas]$ awk '/^$/{print NR}' sed.txt 5

10.4 sort

sort命令是在Linux里非常有用,它将文件进行排序,并将排序结果标准输出。

\1. 基本语法

sort(选项)(参数)

表1-57

选项说明
-n依照数值的大小排序
-r以相反的顺序来排序
-t设置排序时所用的分隔字符
-k指定需要排序的列

参数:指定待排序的文件列表

\2. 案例实操

(0)数据准备

[atguigu@hadoop102 datas]$ touch sort.sh[atguigu@hadoop102 datas]$ vim sort.sh bb:40:5.4bd:20:4.2xz:50:2.3cls:10:3.5ss:30:1.6

(1)按照“:”分割后的第三列倒序排序。

[atguigu@hadoop102 datas]$ sort -t : -nrk 3  sort.sh bb:40:5.4bd:20:4.2cls:10:3.5xz:50:2.3ss:30:1.6

第11 企业真实面试题(重点)

11.1 京东

问题1:使用Linux命令查询file1中空行所在的行号

答案:

[atguigu@hadoop102 datas]$ awk '/^$/{print NR}' sed.txt 5

问题2:有文件chengji.txt内容如下:

张三 40

李四 50

王五 60

使用Linux命令计算第二列的和并输出

[atguigu@hadoop102 datas]$ cat chengji.txt | awk -F " " '{sum+=$2} END{print sum}'150

**11.**2 搜狐&和讯网

问题1:Shell脚本里如何检查一个文件是否存在?如果不存在该如何处理?

\#!/bin/bashif [ -f file.txt ]; thenecho "文件存在!"elseecho "文件不存在!"fi

**11.**3 新浪

问题1:用shell写一个脚本,对文本中无序的一列数字排序

[root@CentOS6-2 ~]# cat test.txt98765432101
[root@CentOS6-2 ~]# sort -n test.txt|awk '{a+=$0;print $0}END{print "SUM="a}'12345678910SUM=55

11.3 金和网络

问题1:请用shell脚本写出查找当前文件夹(/home)下所有的文本文件内容中包含有字符”shen”的文件名称

[atguigu@hadoop102 datas]$ grep -r "shen" /home | cut -d ":" -f 1/home/atguigu/datas/sed.txt/home/atguigu/datas/cut.txt

的列 |

参数:指定待排序的文件列表

\2. 案例实操

(0)数据准备

[atguigu@hadoop102 datas]$ touch sort.sh[atguigu@hadoop102 datas]$ vim sort.sh bb:40:5.4bd:20:4.2xz:50:2.3cls:10:3.5ss:30:1.6

(1)按照“:”分割后的第三列倒序排序。

[atguigu@hadoop102 datas]$ sort -t : -nrk 3  sort.sh bb:40:5.4bd:20:4.2cls:10:3.5xz:50:2.3ss:30:1.6

第11 企业真实面试题(重点)

11.1 京东

问题1:使用Linux命令查询file1中空行所在的行号

答案:

[atguigu@hadoop102 datas]$ awk '/^$/{print NR}' sed.txt 5

问题2:有文件chengji.txt内容如下:

张三 40

李四 50

王五 60

使用Linux命令计算第二列的和并输出

[atguigu@hadoop102 datas]$ cat chengji.txt | awk -F " " '{sum+=$2} END{print sum}'150

**11.**2 搜狐&和讯网

问题1:Shell脚本里如何检查一个文件是否存在?如果不存在该如何处理?

\#!/bin/bashif [ -f file.txt ]; thenecho "文件存在!"elseecho "文件不存在!"fi

11.3 新浪

问题1:用shell写一个脚本,对文本中无序的一列数字排序

[root@CentOS6-2 ~]# cat test.txt98765432101
[root@CentOS6-2 ~]# sort -n test.txt|awk '{a+=$0;print $0}END{print "SUM="a}'12345678910SUM=55

在这里插入图片描述

总的来说,Shell 在大数据技术中有着广泛的应用。通过编写 Shell 脚本,可以进行数据处理、数据清洗和转换、批量处理、任务调度以及系统管理和监控等任务。Shell 的强大文本处理能力和脚本编程特性,使得它成为处理大数据和自动化任务的重要工具。掌握 Shell 编程技巧,将有助于在大数据领域提高工作效率和数据处理的灵活性。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/226774.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Redis设计与实现之对象处理机制

目录 一、前言 二、对象处理机制 1、redisObject 数据结构&#xff0c;以及 Redis 的数据类型 2、 命令的类型检查和多态 3、对象共享 4、引用计数以及对象的销毁 三、对象的处理 1、Redis是如何处理字符串对象的&#xff1f; 2、Redis是如何处理列表对象的&#xff1f…

十九)Stable Diffusion使用教程:ai室内设计案例

今天我们聊聊如何通过SD进行室内设计装修。 方式一:controlnet的seg模型 基础起手式: 选择常用算法,抽卡: 抽到喜欢的图片之后,拖到controlnet里: 选择seg的ade20k预处理器,点击爆炸按钮,得到seg语义分割图,下载下来: 根据语义分割表里的颜色值,到PS里进行修改: 语…

制作一个简单 的maven plugin

流程 首先&#xff0c; 你需要创建一个Maven项目&#xff0c;推荐用idea 创建项目 会自动配置插件 pom.xml文件中添加以下配置&#xff1a; <project> <!-- 项目的基本信息 --> <groupId>com.example</groupId> <artifactId>my-maven-plugi…

深入理解JVM设计的精髓与独特之处

这是Java代码的执行过程 从软件工程的视角去深入拆解&#xff0c;无疑极具吸引力&#xff1a;首个阶段仅依赖于源高级语言的细微之处&#xff0c;而第二阶段则仅仅专注于目标机器语言的特质。 不可否认&#xff0c;在这两个编译阶段之间的衔接&#xff08;具体指明中间处理步…

javacv的视频截图功能

之前做了一个资源库的小项目&#xff0c;因为上传资源文件包含视频等附件&#xff0c;所以就需要时用到这个功能。通过对视频截图&#xff0c;然后作为封面缩略图&#xff0c;达到美观效果。 首先呢&#xff0c;需要准备相关的jar包&#xff0c;之前我用的是低版本的1.4.2&…

极简Excel公式拆分合并单元格并自动填充

例如这个表格&#xff1a; 我们希望拆分合并单元格&#xff0c;并填充到E列。结果如&#xff1a; 步骤 1&#xff09;在E2输入公式如下&#xff1a; LOOKUP(2,1/($B$2:B2<>""),$B$2:B2) 2&#xff09;下拉E2至E9将公式填充即可 注意&#xff1a;公式中的$…

基于ssm游戏美术外包管理信息系统源码和论文

摘 要 随着信息技术和网络技术的飞速发展&#xff0c;人类已进入全新信息化时代&#xff0c;线下管理技术已无法高效&#xff0c;便捷地管理信息。为了迎合时代需求&#xff0c;优化管理效率&#xff0c;各种各样的管理系统应运而生&#xff0c;各行各业相继进入信息管理时代&…

[Linux] Apache的配置与运用

一、web虚拟主机的构台服务器上运行多个网站&#xff0c;每个网站实际上并不独立占用整个服务器&#xff0c;因此称为"虚拟"虚拟主机的虚拟主机服务可以让您充分利用服务器的硬件资源&#xff0c;大大降低了建立和运营网站的成本 Httpd服务使构建虚拟主机服务器变得容…

基于SSM的志愿者管理系统

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;Vue 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#xff1a;是 目录…

6.23删除二叉搜索树中的节点(LC450-M)

算法&#xff1a; 一共有五种可能的情况&#xff1a; 第一种情况&#xff1a;没找到删除的节点&#xff0c;遍历到空节点直接返回了找到删除的节点 第二种情况&#xff1a;左右孩子都为空&#xff08;叶子节点&#xff09;&#xff0c;直接删除节点&#xff0c; 返回NULL为根…

基于springboot乐器视频学习网站设计与实现

项目描述 临近学期结束&#xff0c;还是毕业设计&#xff0c;你还在做java程序网络编程&#xff0c;期末作业&#xff0c;老师的作业要求觉得大了吗?不知道毕业设计该怎么办?网页功能的数量是否太多?没有合适的类型或系统?等等。你想解决的问题&#xff0c;今天给大家介绍…

讲座 | 颠覆传统摄像方式乃至计算机视觉的“脉冲视觉”

传统相机拍摄视频时其实是以一定帧率进行采样&#xff0c;视频其实还是一串图片的集合&#xff0c;因此低帧率时会觉得视频卡&#xff0c;拍摄高速运动物体时会有运动模糊等等问题。然而你能想象这一切都可以被“脉冲视觉”这一前沿技术改变吗&#xff1f; 今天下午听了北京大学…

【从零开始学习JVM | 第七篇】深入了解 堆回收

前言&#xff1a; Java堆作为内存管理中最核心的一部分&#xff0c;承担着对象实例的存储和管理任务。堆内存的高效使用对于保障程序的性能和稳定性至关重要。因此&#xff0c;深入理解Java堆回收的原理、机制和优化策略&#xff0c;对于Java开发人员具有重要的意义。 本文旨在…

C++相关闲碎记录(16)

1、正则表达式 &#xff08;1&#xff09;regex的匹配和查找接口 #include <regex> #include <iostream> using namespace std;void out (bool b) {cout << ( b ? "found" : "not found") << endl; }int main() {// find XML/H…

ProroBuf C++笔记

一.什么是protobuf Protocol Buffers是Google的⼀种语⾔⽆关、平台⽆关、可扩展的序列化结构数据的⽅法&#xff0c;它可⽤于&#xff08;数据&#xff09;通信协议、数据存储等。Protocol Buffers 类⽐于XML&#xff0c;是⼀种灵活&#xff0c;⾼效&#xff0c;⾃动化机制的结…

SpringData自定义操作

一、JPQL和SQL 查询 package com.kuang.repositories;import com.kuang.pojo.Customer; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingR…

javaEE -17(13000字 CSS3 入门级教程)

一&#xff1a;CSS3 简介 CSS3 是 CSS2 的升级版本&#xff0c;它在 CSS2 的基础上&#xff0c;新增了很多强大的新功能&#xff0c;从而解决一些实际面临的问题&#xff0c;CSS3 在未来会按照模块化的方式去发展&#xff1a;https://www.w3.org/Style/CSS/current-work.html …

Guardrails for Amazon Bedrock 基于具体使用案例与负责任 AI 政策实现定制式安全保障(预览版)

作为负责任的人工智能&#xff08;AI&#xff09;战略的一部分&#xff0c;您现在可以使用 Guardrails for Amazon Bedrock&#xff08;预览版&#xff09;&#xff0c;实施专为您的用例和负责任的人工智能政策而定制的保障措施&#xff0c;以此促进用户与生成式人工智能应用程…

智能优化算法应用:基于哈里斯鹰算法3D无线传感器网络(WSN)覆盖优化 - 附代码

智能优化算法应用&#xff1a;基于哈里斯鹰算法3D无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用&#xff1a;基于哈里斯鹰算法3D无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.哈里斯鹰算法4.实验参数设定5.算法结果6.…

linux性能优化-上下文切换

如何理解上下文切换 Linux 是一个多任务操作系统&#xff0c;它支持远大于 CPU 数量的任务同时运行&#xff0c;这是通过频繁的上下文切换、将CPU轮流分配给不同任务从而实现的。 CPU 上下文切换&#xff0c;就是先把前一个任务的 CPU 上下文&#xff08;CPU 寄存器和程序计数…