0

我尝试从文件中提取特定模式。文件内容:

--------some other command in here----------
<tr>
<td>someWords</td>
<td>anotherWords</td>
</tr>
--------some other command in here-----------
the <tr>...</tr> patter occur again

我尝试从文件中提取 tr 模式

在我写的shell脚本中:

读取输入

grep '<tr>\n<td>[A-Za-z0-9,<,>,/]</td>\n<td>[A-Za-z0-9,<,>,/]</td>\n</tr>

但是,此命令不起作用。任何的想法?谢谢

4

1 回答 1

0
 sed -n '/<tr>/,/<\/tr>/p' file

见例子:

kent$  cat a                      
--------some other command in here----------
<tr>
<td>someWords</td>
<td>anotherWords</td>
</tr>
--------some other command in here-----------
the 
<tr>
<td>someOtherWords</td>
<td>anotherWords2</td>
</tr>

kent$  sed -n '/<tr>/,/<\/tr>/p' a
<tr>
<td>someWords</td>
<td>anotherWords</td>
</tr>
<tr>
<td>someOtherWords</td>
<td>anotherWords2</td>
</tr>
于 2013-01-18T23:12:49.430 回答