每次出现输入文件中的"AAA"表达式后,我必须打印81行.我该怎么做?
哇,这在标题中听起来如此复杂,但我认为并非如此.
我有基本上这种布局的文本文件:
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.
让我知道,如果我表达不清楚.我更乐意提供进一步的信息.
输入=
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) 我正在尝试使用以下结构从文本文件中提取数据:
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) 以下代码有效,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)
我在这做错了什么?
我创建了一个批处理文件,它使用FOR命令读取FROM Directory,FROM File,TO Directory,TO File的文件作为参数.(我在目的地给出了新名字的文件)
一切都很好,直到我添加一个新的文件混合.
在XCOPY /i选项中说它是一个目录(不是真的).如果我不使用/i它想知道它是文件还是目录.它始终是一个文件.有没有办法我可以自动回复或有人有其他建议.