[英]Text Transformation in a File with SED
Given the csv file called address.txt : 给定名为address.txt的csv文件:
Buddy,Guy,49085
Otis,Rush,60194
How can I convert the file to just contain the zip code? 如何将文件转换为仅包含邮政编码? My commandline test is not working and I am not sure why.
我的命令行测试无法正常工作,我不确定为什么。 I am getting the untransformed text returned from
cat
我收到了从
cat
返回的未转换文本
cat address.txt | sed 's/\(.+\),\(.+\),\(.+\)/\3/g'
This does it: 这样做:
cat address.txt | sed 's/[^,]*,[^,]*,\([^,]*\)/\1/'
It's easier in sed to describe what the pattern should not contain VS. 使用sed可以更容易地描述什么模式不应该包含VS。 what it should, at least for this problem
至少应该解决这个问题
做到这一点(使用GNU sed):
sed -r 's/.+,(.+)/\1/' address.txt
sed 's/.*,//' address.txt
要么
awk -F, '{print $NF}' address.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.