需要转换下面的awk命令sed的成 [英] Need to convert the below awk command into sed

查看:65
本文介绍了需要转换下面的awk命令sed的成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要转换下面的awk命令进入sed的,结果
的awk -F',''$ 2〜/ ^ * [0-9] *(\\。[0-9] +)?* $ / {子(//,,$ 2 );打印$ 2}

I need to convert the below awk command into sed,
awk -F ',' '$2 ~ /^ *[0-9]*(\.[0-9]+)?" *$/{sub(/"/, "", $2); print $2}'

下面是我的输入文件:

sample.txt的:

sample.txt:

3,3结果
6位,6位结果
74〜10'3-1 / 2,74〜10'3-1 / 2结果
4.8,4.8结果
99到111可调 - 最大148,可调从99到111 - 最大148 搜索

3",3"
6-position,6-position
7' 4" to 10' 3-1/2",7' 4" to 10' 3-1/2"
4.8",4.8"
Adjustable from 99" to 111" - max 148,Adjustable from 99" to 111" - max 148

,我需要如下输出结果

output.txt中:结果

output.txt:

3,3 结果
6位,结果
74〜10'3-1 / 2,结果
4.8,4.8 结果
99到111可调 - 最大148 结果
所以基本上我需要打印的数值为符号等非数字文本需要由空行来代替,用awk命令的问题是2,3和5号线是越来越删除。

3",3
6-position,
7' 4" to 10' 3-1/2",
4.8",4.8
Adjustable from 99" to 111" - max 148,
So basically I need to print the numeric value for the " symbol, other non-numeric text needs to be replaced by a empty line, the problem with awk command is the 2,3 and 5 line is getting removed.

推荐答案

我评论,awk的一班轮没有意义的输入文件。然而,你可以试试这个sed的行:

as I commented, the awk one-liner doesn't make sense for your input file. However you could try this sed line:

sed -r '/^[0-9.]+"$/{s/"$//;n;};s/.*//' file

这适用于输入文件。

kent$  cat file
3"
6-position
7' 4" to 10' 3-1/2"
4.8"
Adjustable from 99" to 111" - max 148    
kent$  sed -r '/^[0-9.]+"$/{s/"$//;n;};s/.*//' file
3


4.8
(here, the last line is empty too.)

修改

删除 -r 选项,并调整sed的新的输入/输出工作:

remove -r option, and adjust the sed to work with new input/output:

sed  's/^\([^,]*,\)\([0-9.]*\)".*$/\1\2/;t;s/^\([^,]*,\).*/\1/' file

这符合您的新的输入例如工作:

This line worked with your new input example:

kent$  cat file
3",3"
6-position,6-position
7' 4" to 10' 3-1/2",7' 4" to 10' 3-1/2"
4.8",4.8"
Adjustable from 99" to 111" - max 148,Adjustable from 99" to 111" - max 148

kent$  sed  's/^\([^,]*,\)\([0-9.]*\)".*$/\1\2/;t;s/^\([^,]*,\).*/\1/' file
3",3
6-position,
7' 4" to 10' 3-1/2",
4.8",4.8
Adjustable from 99" to 111" - max 148,

这篇关于需要转换下面的awk命令sed的成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆