It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
6年前关闭。
大家好,
上面的awk命令出了什么问题,我只得到空文件。
实作为Need to convert the below awk command into sed
sample.txt:
预期的输出是
output.txt:
6年前关闭。
awk -F ',' '$2 ~ /^ *[0-9]*(\.[0-9]+)?" *$/{sub(/"/, "\n", $2);}' sample.txt > out.txt
大家好,
上面的awk命令出了什么问题,我只得到空文件。
实作为Need to convert the below awk command into sed
sample.txt:
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:
3",3
6-position,
7' 4" to 10' 3-1/2",
4.8",4.8
Adjustable from 99" to 111" - max 148,
最佳答案
下面的awk有什么问题
awk -F',''$ 1〜/ ^ [0-9](。[0-9] +)?“ * $ / {sub(/” /,“ \ n”,$ 1);}'
sample.txt> out.txt
只需直接回答您的问题:
假设正则表达式部分正确。您进行了替换,但未打印/输出任何内容。因此您将得到一个空的out.txt
。
编辑
根据您的示例添加有效的awk解决方案:
kent$ awk -F, -v OFS="," '{if($2~/^[0-9.]+"$/)sub(/"/,"",$2);else $2=""}1' file
3",3
6-position,
7' 4" to 10' 3-1/2",
4.8",4.8
Adjustable from 99" to 111" - max 148,
关于linux - 下面的awk有什么问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16502823/