【发布时间】:2023-07-05 01:38:02
【问题描述】:
我想编写一个 shell 脚本,它会从标准输入读取文件,删除所有字符串和空行字符,并将输出写入标准输出。文件如下所示:
#some lines that do not contain <html> in here
<html>a<html>
<tr><html>b</html></tr>
#some lines that do not contain <html> in here
<html>c</html>
所以,输出文件应该包含:
#some lines that do not contain <html> in here
a
<tr>b</html></tr>
#some lines that do not contain <html> in here
c</html>
我尝试编写这个 shell 脚本:
read INPUT #read file from std input
tr -d '[:blank:]'
grep "<html>" | sed -r 's/<html>//g'
echo $INPUT
但是这个脚本根本不起作用。任何的想法?谢谢
【问题讨论】:
-
如果可能的话,您可能想在 Perl(或某个 shell 以外的其他东西)中尝试这个:check out the answer(s) on this other question
-
@summea 我不能。我必须使用 #!/usr/bin/bash
-
应该保留cmets吗?
-
我想我不明白为什么您在一个文档中还有多个
<html></html>对...... -
我也不知道。这只是我老师给我们的一些随机文件
标签: shell