linux grep 过滤多个单词

有时会需要使用 grep 做多关键词匹配,这里给出集中方法,简单记录: grep 'word1\|word2\|word3' /path/to/file ### Search all text files ### $ grep 'word*' *.txt ### Search all python files for 'wordA' or 'wordB' ### $ grep 'wordA*'\''wordB' *.py $ grep -E 'word1|word2' *.doc $ grep -e string1 -e string2 *.pl $ grep -E "word1|word2" *.c ### Show all the lines that do not match given pattern/words/strings ### $ grep -v 'bar\|foo' /dir1/dir2/file1 $ grep -E -v 'pattern1|pattern2' /path/to/file 参考文献 How To Search Multiple Words / String Pattern Using grep Command on Bash shell

October 31, 2022 | 1 分钟 | 115 字 | Tianlun Song

自动递归下载依赖 deb 包 bash 脚本

说明 脚本自动递归下载给定包列表deb包及其依赖包,深度3层; 若指定参数则下载给定的包及其依赖包(目前仅支持指定1个包,不支持多包); 若无参数则默认下载列表中给出的包机器依赖包; 下载到当前目录; 请提前配置好源。 #!/bin/bash logfile=./auto_deps_log # 需要获取其所依赖包的包 # 或者用$1,从命令行输入库名字 libs="gdisk logrotate pciutils systemd lvm2 udev logrotate libfuse2 iptables libnetfilter-conntrack3 libnfnetlink0 libusb-1.0-0 cpio xfsprogs libprotobuf-c1 liblmdb0" ret="" function getDepends() { echo "fileName is" $1>>$logfile # use tr to del < > ret=`apt-cache depends $1|grep Depends |cut -d: -f2 |tr -d "<>"` echo $ret|tee -a $logfile } if [ ! -n "$*" ] ;then echo "you have not input a word! get list: $libs" else echo "the list you input is $*" libs=$1 fi echo "get $libs" # download libs dependen. deep in 3 i=0 while [ $i -lt 3 ] ; do let i++ echo $i # download libs newlist=" " for j in $libs do added="$(getDepends $j)" newlist="$newlist $added" apt-get download $added $j done libs=$newlist done 参考文献 shell获取命令行参数 apt一键下载deb包及其依赖

September 18, 2021 | 1 分钟 | 282 字 | Tianlun Song