"无法读取文件夹"调用sed时出错

时间:2017-02-09 18:53:08

标签: linux bash sed

我试图找到"机器人"在一个巨大的日志文件中。他们都会在一秒钟内登录,更改密码并注销所有内容。

我想编写Bash命令,显示符合以下条件的所有配置文件:

  • 用户登录,用户更改密码,用户在同一秒内注销(所有3个操作必须在1秒内完成)
  • 这些操作(登录,更改,注销)一个接一个地发生,而其间没有其他条目

fxsciaqulmlk是日志文件中的典型配置文件名称。

日志文件的一小部分:

Mon, 22 Aug 2016 13:15:39 +0200|178.57.66.225|fxsciaqulmlk| - |user logged in| -
Mon, 22 Aug 2016 13:15:39 +0200|178.57.66.225|fxsciaqulmlk| - |user changed password| -
Mon, 22 Aug 2016 13:15:39 +0200|178.57.66.225|fxsciaqulmlk| - |user logged off| -
Mon, 22 Aug 2016 13:15:42 +0200|178.57.66.225|faaaaaa11111| - |user logged in| -
Mon, 22 Aug 2016 13:15:49 +0200|178.57.66.215|terdsfsdfsdf| - |user logged in| -
Mon, 22 Aug 2016 13:15:49 +0200|178.57.66.215|terdsfsdfsdf| - |user changed password| -
Mon, 22 Aug 2016 13:15:49 +0200|178.57.66.215|terdsfsdfsdf| - |user logged off| -
Mon, 22 Aug 2016 13:15:59 +0200|178.57.66.205|erdsfsdfsdf| - |user logged in| -
Mon, 22 Aug 2016 13:15:59 +0200|178.57.66.205|erdsfsdfsdf| - |user logged in| -
Mon, 22 Aug 2016 13:15:59 +0200|178.57.66.205|erdsfsdfsdf| - |user changed password| -
Mon, 22 Aug 2016 13:15:59 +0200|178.57.66.205|erdsfsdfsdf| - |user logged off| -
Mon, 22 Aug 2016 13:17:50 +0200|178.57.66.205|abcbbabab| - |user logged in| -
Mon, 22 Aug 2016 13:17:50 +0200|178.57.66.205|abcbbabab| - |user changed password| -
Mon, 22 Aug 2016 13:17:50 +0200|178.57.66.205|abcbbabab| - |user changed profile| -
Mon, 22 Aug 2016 13:17:50 +0200|178.57.66.205|abcbbabab| - |user logged off| -
Mon, 22 Aug 2016 13:19:19 +0200|178.56.66.225|fxsciulmla| - |user logged in| -
Mon, 22 Aug 2016 13:19:19 +0200|178.56.66.225|fxsciulmla| - |user changed password| -
Mon, 22 Aug 2016 13:19:19 +0200|178.56.66.225|fxsciulmla| - |user logged off| -
Mon, 22 Aug 2016 13:20:42 +0200|178.57.67.225|faaaa0a1111| - |user logged in| -

我写了这段代码:

#!/bin/bash
sed '
    /logged in\s*$/! d
    :1
    $! N
    /logged in\s*$/D
    /\(logged \(in\|off\)\|changed password\)$/! s/\n[^\n]*$//
    /logged off$/! b1
    ' /home/indra/Desktop/Untitled Folder/log.txt

但是当我尝试运行此代码时,我得到了这个按摩:

sed: can't read Folder/log.txt: No such file or directory

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

Untitled Folder周围加上引号,因为它包含空格。并且可能在第一列中启动所有sed输入。

#!/bin/bash
sed '
/logged in\s*$/! d
:1
$! N
/logged in\s*$/D
/\(logged \(in\|off\)\|changed password\)$/! s/\n[^\n]*$//
/logged off$/! b1
    ' /home/indra/Desktop/"Untitled Folder"/log.txt