在UNIX中查找和删除 [英] Find and remove in unix
本文介绍了在UNIX中查找和删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的输入文件:
sample.txt
:
3"
6-position
7' 4" to 10' 3-1/2"
4.8"
Adjustable from 99" to 111" - max 148
,在输出中,我只需要3,即
and in the output I only need 3, i.e.
output.txt
:
3
4.8
所以基本上我需要打印"
符号的数字值,其他非数字文本需要完全删除.
So basically I need to print the numeric value for the "
symbol, other non-numeric text needs to be removed entirely.
我试图用sed
来实现这一点,但是我无法获得期望的结果.
I tried to implement this with sed
, but I was not able to get the desired result.
有什么方法可以在UNIX上实现这一目标吗?
Is there any way to achieve this on UNIX?
推荐答案
awk更适合执行此类任务:
awk is more suited to perform this type of task:
awk '/^ *[0-9]*(\.[0-9]+)?" *$/{sub(/"/, ""); print}' inFile
输出:
3
4.8
这篇关于在UNIX中查找和删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文