[英]awk to print some parameters of a line
I have lines in a file in linux, and i am trying print the line without the |
我在linux中的文件中有行,我正在尝试打印没有
|
的行 and without some parameters 没有一些参数
$cat file
2013-07-15,Provider 1.99,3|30000055|2347|0,12222,1,3,0,0,0,19,aaa,bbb
2013-07-15,Provider 1.99,3|30000055|2347|0,12222,44,12,0,0,0,33,aaa,bbb
and i need the output like: 我需要输出像:
2013-07-15,Provider,2347,12222,1,3,0,0,0,19,aaa,bbb
2013-07-15,Provider,2347,12222,44,12,0,0,0,33,aaa,bbb
and i am trying with awk, but i have some problems. 我正在尝试使用awk,但我遇到了一些问题。
If your lines have similar pattern you would to retain then you can do: 如果您的线条具有类似的模式,您可以保留:
awk 'BEGIN{FS=OFS=","}{$2="Provider";$3=2347}1' file
If you don't know what the patterns are then here is a more generic one: 如果您不知道模式是什么,那么这里是一个更通用的模式:
awk 'BEGIN{FS=OFS=","}{split($2,a,/ /);split($3,b,/\|/);$2=a[1];$3=b[3]}1' file
If it doesn't solve your problem, I am pretty sure it would help you guide to get one. 如果它不能解决您的问题,我很确定它可以帮助您指导获得一个问题。
Use awk, and let blank or comma or pipe be the field separators: 使用awk,让空格或逗号或管道为字段分隔符:
awk -F '[[:blank:],|]' -v OFS=, '{
print $1,$2,$6,$8,$9,$10,$11,$12,$13,$14,$15,$16
}' file
2013-07-15,Provider,2347,12222,1,3,0,0,0,19,aaa,bbb
2013-07-15,Provider,2347,12222,44,12,0,0,0,33,aaa,bbb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.