Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 删除文件txt中没有模式的所有字符_Linux - Fatal编程技术网

Linux 删除文件txt中没有模式的所有字符

Linux 删除文件txt中没有模式的所有字符,linux,Linux,我有一个非常大的文件,其中包含模式中的信息: 0 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>274</font> 1 <font color='#888a85'>=&gt;</font> <small>int</small> <font col

我有一个非常大的文件,其中包含模式中的信息:

 0 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>274</font>
 1 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>284</font>
 2 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>299</font>
 3 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>296</font>
 4 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>273</font>
模式是:

'#4e9a06'>[0-9]*</font>
但我仍然有:

'>274</font>
'>284</font>
'>299</font>
'>296</font>
'>273</font>
'>272</font>
但这不是工作。你能帮我把剩下的木炭去掉吗?
谢谢您的回答。

假设您有一个名为
copy.txt的文件,其中存储了您的信息。然后你就跑:

cat copy.txt |egrep -o ">[0123456789]+<"|tr -d  "<"|tr -d ">"

cat copy.txt | egrep-o”>[0123456789]+[1-9][0-9]*请尝试以下操作:

sed -e "s#.*>\([0-9]*\)</font>\$#\\1#" source.txt >out.txt
sed-e“s#.*>\([0-9]*\)\$\\\1#“source.txt>out.txt

我有一个使用Python的解决方案:

$ python -c 'import re,sys; print "\n".join(",".join(j for j in re.findall("06'\''>(.*)</fo", i)) for i in sys.stdin)' <xy
274
284
299
296
273

$python-c'import re,sys;print“\n”.join(“,”).join(在re.findall(“06'\''>(*)中j代表j)请不要用正则表达式解析html

cat<<EOF | html2text | perl -lne 'print for /int (\d+)/g'
0 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>274</font>
1 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>284</font>
2 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>299</font>
3 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>296</font>
4 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>273</font>
EOF
cat copy.txt |egrep -o ">[1-9][0-9]*<"|tr -d  "<"|tr -d ">"
sed -e "s#.*>\([0-9]*\)</font>\$#\\1#" source.txt >out.txt
$ python -c 'import re,sys; print "\n".join(",".join(j for j in re.findall("06'\''>(.*)</fo", i)) for i in sys.stdin)' <xy
274
284
299
296
273
cat<<EOF | html2text | perl -lne 'print for /int (\d+)/g'
0 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>274</font>
1 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>284</font>
2 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>299</font>
3 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>296</font>
4 <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>273</font>
EOF
274
284
299
296
273