我尝试从文件中提取特定模式。文件内容:
--------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脚本中的:
阅读INPUT
grep '<tr>\n<td>[A-Za-z0-9,<,>,/]</td>\n<td>[A-Za-z0-9,<,>,/]</td>\n</tr>
但是,此命令不起作用。任何的想法? THX
答案 0 :(得分: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>