简体   繁体   English

使用 awk、sed 等命令从文件中删除字段

[英]Remove field from file using commands like awk, sed

I need to remove the timezone section from the timestamp using awk.我需要使用 awk 从时间戳中删除时区部分。

File entry:文件入口:

2015-09-30 07:01:33,979 test1

Expected output:预期输出:

2015-09-30 07:01:33 test1

awk to the rescue! awk来救援!

$ echo "2015-09-30 07:01:33,979 test1" | awk -F"[ ,]" '{print $1,$2,$4}' 
2015-09-30 07:01:33 test1

or或者

$ echo "2015-09-30 07:01:33,979 test1" | awk '{sub(/,.* /," ")}1'
2015-09-30 07:01:33 test1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM