小编Dan*_*Bee的帖子

匹配模式后打印特定行数

每次出现输入文件中的"AAA"表达式后,我必须打印81行.我该怎么做?

regex perl awk sed pattern-matching

8
推荐指数
4
解决办法
5928
查看次数

从文本文件中的重复范围模式中获取特定行

哇,这在标题中听起来如此复杂,但我认为并非如此.

我有基本上这种布局的文本文件:

Stimulus ...
...
...
...
Response
Stimulus ...
...
...
...
Response
Run Code Online (Sandbox Code Playgroud)

我使用sed获取介于两者之间的所有内容,然后进一步提取我需要的信息.

sed -n -e '/Stimulus/,/Response/ p'
Run Code Online (Sandbox Code Playgroud)

但是,有时参与者不响应,在这种情况下文件看起来像这样:

Stimulus ...
...
...
...
Stimulus ...
...
...
...
Response
Run Code Online (Sandbox Code Playgroud)

在这种特殊情况下,我的脚本将无法获得我想要的内容.所以,我正在寻找一种方法来提取信息,当且仅当pattern1后面跟着pattern2,而不是pattern1.

让我知道,如果我表达不清楚.我更乐意提供进一步的信息.

regex perl awk sed pattern-matching

6
推荐指数
2
解决办法
180
查看次数

删除行中的所有空格,但不删除双引号之间的空格

例:

输入=

This is an example text with    some      spaces. 
This should be 2nd line.
However the spaces between "quotes    should not    change".
last line.
Run Code Online (Sandbox Code Playgroud)

输出=

Thisisanexampletextwithsomespaces. 
Thisshouldbe2ndline.
Howeverthespacesbetween"quotes    should not    change".
lastline.
Run Code Online (Sandbox Code Playgroud)

regex perl awk sed pattern-matching

5
推荐指数
1
解决办法
1493
查看次数

从文本文件中获取数据

我正在尝试使用以下结构从文本文件中提取数据:

Employee: John C.
  2013-01-01  10  $123
  2013-01-02  12  $120
  2013-01-03  8  $150
Employee: Michael G.
  2013-01-01  5  $13
  2013-01-05  11  $20
  2013-01-10  2  $155
Run Code Online (Sandbox Code Playgroud)

如您所见,模式是一个包含Employee名称的表头,然后是包含其所有事务的表内容,然后重复模式.

要提取交易,我这样做:

awk '/^  [A-Z]/{print $1"\t"$2"\t"$3}'
Run Code Online (Sandbox Code Playgroud)

这给出了这个结果:

  2013-01-01  10  $123
  2013-01-02  12  $120
  2013-01-03  8   $150
  2013-01-01  5   $13
  2013-01-05  11  $20
  2013-01-10  2   $155
Run Code Online (Sandbox Code Playgroud)

如何创建一个返回此的两遍提取:

  2013-01-01  10  $123  John C.
  2013-01-02  12  $120  John C.
  2013-01-03  8   $150  John C.
  2013-01-01  5   $13   Michael G.
  2013-01-05  11  $20   Michael G.
  2013-01-10  2   $155  Michael …
Run Code Online (Sandbox Code Playgroud)

regex perl awk sed pattern-matching

3
推荐指数
1
解决办法
111
查看次数

内部循环查找和替换[批处理脚本]

以下代码有效,echo test.test

set replaceWith=.
set str="test\test"
call set str=%%str:\=%replaceWith%%%
echo %str%
Run Code Online (Sandbox Code Playgroud)

但是,下面的代码回显ggg.hhhhh全部4次.

SET SERVICE_LIST=(aaa\bbb ccc\dddd eeee\fffff ggg\hhhhh)

for %%i in %SERVICE_LIST% do (
set replaceWith=.
set str="%%i"
call set str=%%str:\=%replaceWith%%%
echo %str%
)
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

windows for-loop cmd batch-file pattern-matching

2
推荐指数
2
解决办法
5303
查看次数

Windows批量自动扫描XCOPY/i

我创建了一个批处理文件,它使用FOR命令读取FROM Directory,FROM File,TO Directory,TO File的文件作为参数.(我在目的地给出了新名字的文件)

一切都很好,直到我添加一个新的文件混合.

XCOPY /i选项中说它是一个目录(不是真的).如果我不使用/i它想知道它是文件还是目录.它始终是一个文件.有没有办法我可以自动回复或有人有其他建议.

windows cmd batch-file

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

标签 统计

pattern-matching ×5

awk ×4

perl ×4

regex ×4

sed ×4

batch-file ×2

cmd ×2

windows ×2

for-loop ×1