shell脚本学习(三)
2024-08-24 18:04:37
1、在grep中, ^标记着单词的开始, $ 标记着单词的结束。
查看一个单词是否在linux自带的词典中,脚本如下:
#bin/sh
#文件名:checkword.sh
word=$1
grep "^$1$" /usr/share/dict/american-english -q
if [ $? -eq 0 ]; then
echo $word is a dictionary word;
else
echo $word is not a dictionary word;
fi
2、echo -e 中 -e 表明echo 会解释转义序列。
例如: echo -e "1\nhello\n"
等于 1 回车
hello 回车
3、sed中的s表示替换(substitute)。
例如: comm a.txt b.txt -3 | sed 's/^\t//'
hbg@root:~/dl$ comm a.txt b.txt -3
apple
carrot
cookies
iron
silver
steel
hbg@root:~/dl$ comm a.txt b.txt -3 | sed 's/^\t//'
apple
carrot
cookies
iron
silver
steel
最新文章
- java 学习框架
- px 与 dp, sp换算公式?
- fstream使用简介
- python开发_++i,i += 1的区分
- Python之路【第十一篇续】前端初识之CSS
- hdu 4007 暴力or线段树 ***
- 通过反汇编理解函数调用机制(x86和ARM)
- JAVA开发--U盘EXE恢复工具
- 【原】Kryo序列化篇
- PHP操作Oracle数据库
- Linq101-Restriction
- 手把手教你用vue-cli搭建vue项目
- 关注Yumiot公众号,了解最新的物联网资讯
- web自动化上传附件 2
- 递归 + OS模块
- go 调用windows dll 的三种方法
- vim 初识
- 延时显示(类QQ头像显示)
- 读取properties文件的信息
- C# 数据上传(自用笔记)