小编Sky*_*969的帖子

管道grep和使用正则表达式

基本上我想要做的是解析文件中的行并返回用户名.用户名总是包含在<和>中,所以我想使用正则表达式来匹配(包括)<和之后的所有内容(包括)之后的eveything,然后反转我的匹配.我明白grep -vE应该能够做到这一点.

到目前为止,我的脚本看起来像这样:

#!/bin/bash
while read line; do
        echo $line | grep -vE '(.*<)|(>.*)'
done < test_log
Run Code Online (Sandbox Code Playgroud)

test_log包含以下内容:

Mar  1 09:28:08 (IP redacted) dovecot: pop3-login: Login: user=<emcjannet>, method=PLAIN, rip=(IP redacted), lip=(IP redacted)
Mar  1 09:27:53 (IP redacted) dovecot: pop3-login: Login: user=<dprotzak>, method=PLAIN, rip=(IP redacted), lip=(IP redacted)
Mar  1 09:28:28 (IP redacted) dovecot: imap-login: Login: user=<gconnie>, method=PLAIN, rip=(IP redacted), lip=(IP redacted), TLS
Mar  1 09:27:25 (IP redacted) dovecot: imap-login: Login: user=<gconnie>, method=PLAIN, rip=(IP redacted), lip=(IP redacted), TLS
Run Code Online (Sandbox Code Playgroud)

但是,在运行我的脚本时,没有返回任何内容,尽管当我使用反向匹配测试regex之类的正则表达式时它完全符合我的要求.我究竟做错了什么?

regex bash

9
推荐指数
2
解决办法
1万
查看次数

错误:说明=查询无效

由于混乱的组策略对象,多个计算机不应安装TightVNC.GPO已经不见了,所以从那里删除软件并不是我所知道的选项.因此,我正在编写脚本以便从计算机列表中删除PowerShell.

这是我的脚本:

if ($args.length -ne 1) {
    Write-Warning "Must pass computer name, ending script.";
    break
}

$pc = $args[0]

Write-Output "Scanning $pc for TightVNC...."
$prod = wmic /node:$pc product get name | where {$_ -match "TightVNC"}
if ($prod) {
    Write-Output "Found TightVNC, attempting uninstall...."
    wmic /node:$pc product where name="TightVNC" call uninstall
} else {
    Write-Warning "Could not find TightVNC on $pc."
}
Write-Output "Done."
Run Code Online (Sandbox Code Playgroud)

现在,我的输出如下:

Scanning [computer] for TightVNC....
Found TightVNC, attempting uninstall....
ERROR:
Description = Invalid query
Done.
Run Code Online (Sandbox Code Playgroud)

但是,如果我将第二个wmic行复制并粘贴到一个提升的命令提示符并用[computer]替换$ …

powershell powershell-2.0

4
推荐指数
1
解决办法
6159
查看次数

批处理 - 删除一周的备份

所以我有一个批处理文件将文件夹备份到我的Google云端硬盘目录,如下所示:

C:\Program Files\WinRAR\rar.exe a -r "D:\Google Drive\Saves Backup\%DATE%.rar" "D:\Documents\My Games\"
Run Code Online (Sandbox Code Playgroud)

这会在适当的文件夹中生成一个名为30-Sep-12.rar(今天运行)的文件.

但是,我的问题是:有没有办法通过所述文件夹(D:\ Google Drive\Saving Backup)并删除超过一周的备份,由文件名确定?

backup batch-file

0
推荐指数
1
解决办法
1776
查看次数

标签 统计

backup ×1

bash ×1

batch-file ×1

powershell ×1

powershell-2.0 ×1

regex ×1