随笔分类 -  linux shell

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 78 下一页
摘要:001、 [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt 5 8 2 7 3 [root@pc1 test1]# awk '{if(NR == 1) {idx = NR; value = $1}; if($1 > value) {idx 阅读全文
posted @ 2024-03-16 11:57 小鲨鱼2018 阅读(34) 评论(0) 推荐(0)
摘要:001、脚本解释器用于说明程序执行的方式。 [root@pc1 test1]# ls ## 两个测试脚本, test02.script 相比于test01.script多了指定python解释器的语句 #!/usr/bin/env python test01.script test02.script 阅读全文
posted @ 2024-03-08 16:56 小鲨鱼2018 阅读(34) 评论(0) 推荐(0)
摘要:001、为了避免脚本多次执行,生成结果多次追加,可以在追加语句的前面增加清空语句避免多次追加 [root@pc1 test1]# ls a.sh [root@pc1 test1]# cat a.sh ## 测试脚本 #!/bin/bash > result.txt ## 或者使用 rm -f res 阅读全文
posted @ 2024-03-06 10:59 小鲨鱼2018 阅读(72) 评论(0) 推荐(0)
摘要:001、在特定的情况下,为了防止脚本重复执行,造成混乱,可以在末尾追加如下语句避免脚本重复执行 [root@pc1 test1]# ls a.sh [root@pc1 test1]# cat a.sh ## 测试脚本 #!/bin/bash seq 2 seq 2 sed -i 's/^/#/' $ 阅读全文
posted @ 2024-03-06 10:44 小鲨鱼2018 阅读(152) 评论(0) 推荐(0)
摘要:linux 中declare命令的用法 001、声明整数型变量 [root@pc1 test1]# declare -i var1 ## 声明变量为整数型变量 [root@pc1 test1]# var1=132 ## 赋值整数型变量 [root@pc1 test1]# echo $var1 ## 阅读全文
posted @ 2024-03-04 19:53 小鲨鱼2018 阅读(527) 评论(0) 推荐(0)
摘要:linux shell脚本中 =~ 的作用 =~ 表示正则表达式左侧是否匹配右侧。 001、举例如下: [root@pc1 test1]# str1=12343 ## 纯数字字符串 [root@pc1 test1]# str2=abdef ## 字母字符串 [root@pc1 test1]# str 阅读全文
posted @ 2024-03-04 12:22 小鲨鱼2018 阅读(2040) 评论(0) 推荐(0)
摘要:linux 中如何判断变量是否为数值 001、 利用正则表达式判断 a、 [root@pc1 test1]# str1="abcd" ## 字母字符串 [root@pc1 test1]# str2="100" ## 数字字符串 [root@pc1 test1]# re="^[-+]?[0-9]+([ 阅读全文
posted @ 2024-03-04 12:16 小鲨鱼2018 阅读(286) 评论(0) 推荐(0)
摘要:linux 中正则表达式中?号的作用是匹配前面的字母0次或者1次; 001、测试如下: [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt ## 测试样本 abcd xyz 133 kkkk abde jjj dddu abbcde jjj 阅读全文
posted @ 2024-03-04 12:13 小鲨鱼2018 阅读(126) 评论(0) 推荐(0)
摘要:001、 [root@pc1 test2]# ls a.txt [root@pc1 test2]# cat a.txt ## 测试数据 xx yy$ kk ff ee 88 uu ee ww$ [root@pc1 test2]# grep "$" a.txt ## grep直接检测,检测不到 xx 阅读全文
posted @ 2024-03-01 16:02 小鲨鱼2018 阅读(99) 评论(0) 推荐(0)
摘要:linux 中条件测试 case 语句。 case语句用于多重判断匹配;若匹配成功,则执行相关的命令,并结束整个条件测试;若匹配不成功,则执行默认的命令; linux shell 中case 条件判断的首个单词是case, 第一句的结束是 in; 单项匹配判断的结尾是); 单项匹配的结束时两个分号; 阅读全文
posted @ 2024-02-28 08:42 小鲨鱼2018 阅读(89) 评论(0) 推荐(0)
摘要:linux shell 中实现进度条: #! /bin/bash total_steps=100 for ((step=1; step<=total_steps; step++)); do printf "\r[%-50s] %d%%" $(printf "#%.0s" $(seq 1 $((ste 阅读全文
posted @ 2024-02-27 11:53 小鲨鱼2018 阅读(539) 评论(0) 推荐(0)
摘要:linux 中 printf "\r" 选项的作用 使用printf "\r"将光标移动到当前行的开头,用新文本覆盖掉同一行之前的文本内容。 阅读全文
posted @ 2024-02-27 11:24 小鲨鱼2018 阅读(108) 评论(0) 推荐(0)
摘要:001、设置占位长度 [root@pc1 test1]# printf "%s\n" "abc" ## 一般输出 abc [root@pc1 test1]# printf "%20s\n" "abc" ## 设置占位长度20,默认情况下是右对齐 abc [root@pc1 test1]# print 阅读全文
posted @ 2024-02-27 10:04 小鲨鱼2018 阅读(115) 评论(0) 推荐(0)
摘要:001、不加参数对比 [root@pc1 test1]# ls ## 测试文件及目录 dir1 dir2 dir3 dir4 file1 file2 [root@pc1 test1]# du -sh ## 输出了当前目录的所有目录及文件的总的大小 1.3G . [root@pc1 test1]# d 阅读全文
posted @ 2024-02-25 12:07 小鲨鱼2018 阅读(1526) 评论(0) 推荐(0)
摘要:001、 [root@pc1 test1]# ls ## 测试文件及目录 dir1 dir2 dir3 dir4 file1 file2 [root@pc1 test1]# du -ch ## 显示所有文件及目录的大小 220M ./dir1 530M ./dir2 6.6M ./dir3/dir0 阅读全文
posted @ 2024-02-25 11:54 小鲨鱼2018 阅读(173) 评论(0) 推荐(0)
摘要:001、首选测试awk中getline这个动作 做了什么 a、 [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt ## 测试数据 01 02 03 04 05 06 kk 07 08 09 10 11 12 13 14 [root@pc1 阅读全文
posted @ 2024-02-23 09:46 小鲨鱼2018 阅读(83) 评论(0) 推荐(0)
摘要:001、sin 正玄; 直角三角形对边除以斜边;awk的sin函数用于计算正玄,但是单位是弧度; 角度和弧度的转换关系为:角度 * π / 180 = 弧度 如下示例计算30度角和60度角的正玄值: [root@pc1 test1]# echo | awk '{print sin(30 * 3.14 阅读全文
posted @ 2024-02-23 09:45 小鲨鱼2018 阅读(91) 评论(0) 推荐(0)
摘要:001、awk中sub函数的用法:sub用于替换,其语法如下: a、 [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt ## 测试数据 abcdxabcd abcd xyz qmn opqriytyx abcd uny een abcdka 阅读全文
posted @ 2024-02-23 09:44 小鲨鱼2018 阅读(2554) 评论(0) 推荐(0)
摘要:001、 [root@PC1 test1]# ls a.txt [root@PC1 test1]# cat a.txt ## 测试文本 abcdabcd xyabdada kkkrrrtt faaafert [root@PC1 test1]# sed -r 's/(.*)(a)(.*$)/\1\3/ 阅读全文
posted @ 2024-02-21 15:01 小鲨鱼2018 阅读(367) 评论(0) 推荐(0)
摘要:001、ARGC :命令行参数数组ARGV中元素的个数(c:count; v:variable) [root@PC1 test1]# ls a.txt b.txt [root@PC1 test1]# awk '{print ARGC}' a.txt ## ARGC:表示命令行参数数组ARGV中元素的 阅读全文
posted @ 2024-02-20 23:10 小鲨鱼2018 阅读(26) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 78 下一页