Linux bash 脚本 -

标签 linux bash grep

我试图使用一行是否包含日期作为 if 语句的条件:

if [grep -n -v '[0-9][0-9][0-9][0-9]' $line |wc -l==0]
then
...

上面返回一个错误。我不一定需要使用 grep。 grep 处理的行如下所示:

1984 Dan Marino QB Miami Dolphins 

感谢任何帮助。

最佳答案

if [[ $(echo $line | grep -q '[0-9][0-9][0-9][0-9]') ]]; then

# do something
fi

关于Linux bash 脚本 -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16972330/

相关文章:

git - 监视文件更改并在新文件出现时调用 git commit

bash - sed 从文件中提取部分字符串

linux - sed:删除包含字符类的整个单词

linux - bash: “export: command not found... -bash: export: `/usr/local/git/bin': 打开终端时不是有效标识符

linux - 使用 sed 将 grep 的结果添加到文件的第二行

RegEx:获取多行 LDAP 条目

linux - 难以解决:- “SCP copies files successfully, but files not visible in local computer”

linux - 如何从 shell 脚本中变量中存储的日期中减去年份?

linux - 如何使用 libcurl Xively HTTP PUT

linux - 使 Tar + gzip 忽略目录路径