我有一个文件(/etc/passwd),它有上千行,如:
nom de login:password:uid:gid:nom en clair:home dir:shell我想保留'nom en clair‘字段,并使用sed 's/..etc..删除其他部分
我该怎么做?
我使用以下表达式在vi中完成了该操作:
:%s#\%([^:]\+:\)\{4}\([^:]\+\).*#\1发布于 2014-10-02 14:05:07
使用awk
s='nom de login:password:uid:gid:nom en clair: home dir:shell'
awk -F: '{print $5}' <<< "$s"
nom en clair使用sed
sed 's/^\([^:]*:\)\{4\}\([^:]*\).*$/\2/' <<< "$s"
nom en clairhttps://stackoverflow.com/questions/26162497
复制相似问题